mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Rollup merge of #152883 - mu001999-contrib:fix/final-bad-use, r=Kivooeo
Deny final not followed by item Fixes rust-lang/rust#152820
This commit is contained in:
@@ -2203,6 +2203,15 @@ pub(crate) struct DefaultNotFollowedByItem {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`final` is not followed by an item")]
|
||||
#[note("only associated functions in traits may be prefixed by `final`")]
|
||||
pub(crate) struct FinalNotFollowedByItem {
|
||||
#[primary_span]
|
||||
#[label("the `final` qualifier")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
pub(crate) enum MissingKeywordForItemDefinition {
|
||||
#[diag("missing `enum` for enum definition")]
|
||||
|
||||
@@ -197,6 +197,8 @@ pub(super) fn parse_item_common(
|
||||
|
||||
if let Defaultness::Default(span) = def {
|
||||
this.dcx().emit_err(errors::DefaultNotFollowedByItem { span });
|
||||
} else if let Defaultness::Final(span) = def {
|
||||
this.dcx().emit_err(errors::FinalNotFollowedByItem { span });
|
||||
}
|
||||
|
||||
if !attrs_allowed {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#![feature(final_associated_functions)]
|
||||
|
||||
fn main() {
|
||||
final; //~ ERROR `final` is not followed by an item
|
||||
final 1 + 1; //~ ERROR `final` is not followed by an item
|
||||
final { println!("text"); }; //~ ERROR `final` is not followed by an item
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
error: `final` is not followed by an item
|
||||
--> $DIR/bad-positions.rs:4:5
|
||||
|
|
||||
LL | final;
|
||||
| ^^^^^ the `final` qualifier
|
||||
|
|
||||
= note: only associated functions in traits may be prefixed by `final`
|
||||
|
||||
error: `final` is not followed by an item
|
||||
--> $DIR/bad-positions.rs:5:5
|
||||
|
|
||||
LL | final 1 + 1;
|
||||
| ^^^^^ the `final` qualifier
|
||||
|
|
||||
= note: only associated functions in traits may be prefixed by `final`
|
||||
|
||||
error: `final` is not followed by an item
|
||||
--> $DIR/bad-positions.rs:6:5
|
||||
|
|
||||
LL | final { println!("text"); };
|
||||
| ^^^^^ the `final` qualifier
|
||||
|
|
||||
= note: only associated functions in traits may be prefixed by `final`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Reference in New Issue
Block a user