File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2203,6 +2203,15 @@ pub(crate) struct DefaultNotFollowedByItem {
22032203 pub span : Span ,
22042204}
22052205
2206+ #[ derive( Diagnostic ) ]
2207+ #[ diag( "`final` is not followed by an item" ) ]
2208+ #[ note( "only associated functions in traits may be prefixed by `final`" ) ]
2209+ pub ( crate ) struct FinalNotFollowedByItem {
2210+ #[ primary_span]
2211+ #[ label( "the `final` qualifier" ) ]
2212+ pub span : Span ,
2213+ }
2214+
22062215#[ derive( Diagnostic ) ]
22072216pub ( crate ) enum MissingKeywordForItemDefinition {
22082217 #[ diag( "missing `enum` for enum definition" ) ]
Original file line number Diff line number Diff line change @@ -197,6 +197,8 @@ impl<'a> Parser<'a> {
197197
198198 if let Defaultness :: Default ( span) = def {
199199 this. dcx ( ) . emit_err ( errors:: DefaultNotFollowedByItem { span } ) ;
200+ } else if let Defaultness :: Final ( span) = def {
201+ this. dcx ( ) . emit_err ( errors:: FinalNotFollowedByItem { span } ) ;
200202 }
201203
202204 if !attrs_allowed {
Original file line number Diff line number Diff line change 1+ #![ feature( final_associated_functions) ]
2+
3+ fn main ( ) {
4+ final; //~ ERROR `final` is not followed by an item
5+ final 1 + 1 ; //~ ERROR `final` is not followed by an item
6+ final { println!( "text" ) ; } ; //~ ERROR `final` is not followed by an item
7+ }
Original file line number Diff line number Diff line change 1+ error: `final` is not followed by an item
2+ --> $DIR/bad-positions.rs:4:5
3+ |
4+ LL | final;
5+ | ^^^^^ the `final` qualifier
6+ |
7+ = note: only associated functions in traits may be prefixed by `final`
8+
9+ error: `final` is not followed by an item
10+ --> $DIR/bad-positions.rs:5:5
11+ |
12+ LL | final 1 + 1;
13+ | ^^^^^ the `final` qualifier
14+ |
15+ = note: only associated functions in traits may be prefixed by `final`
16+
17+ error: `final` is not followed by an item
18+ --> $DIR/bad-positions.rs:6:5
19+ |
20+ LL | final { println!("text"); };
21+ | ^^^^^ the `final` qualifier
22+ |
23+ = note: only associated functions in traits may be prefixed by `final`
24+
25+ error: aborting due to 3 previous errors
26+
You can’t perform that action at this time.
0 commit comments