Auto merge of #127419 - trevyn:issue-125446, r=fee1-dead

Add suggestions for possible missing `fn`, `struct`, or `enum` keywords

Closes #125446
Closes #65381
This commit is contained in:
bors 2024-07-10 18:27:32 +00:00
commit 0c81f94b9a
42 changed files with 308 additions and 146 deletions

View File

@ -1,9 +1,5 @@
parse_add_paren = try adding parentheses parse_add_paren = try adding parentheses
parse_ambiguous_missing_keyword_for_item_definition = missing `fn` or `struct` for function or struct definition
.suggestion = if you meant to call a macro, try
.help = if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier
parse_ambiguous_range_pattern = the range pattern here has ambiguous interpretation parse_ambiguous_range_pattern = the range pattern here has ambiguous interpretation
.suggestion = add parentheses to clarify the precedence .suggestion = add parentheses to clarify the precedence
@ -528,14 +524,23 @@ parse_missing_comma_after_match_arm = expected `,` following `match` arm
parse_missing_const_type = missing type for `{$kind}` item parse_missing_const_type = missing type for `{$kind}` item
.suggestion = provide a type for the item .suggestion = provide a type for the item
parse_missing_enum_for_enum_definition = missing `enum` for enum definition
.suggestion = add `enum` here to parse `{$ident}` as an enum
parse_missing_enum_or_struct_for_item_definition = missing `enum` or `struct` for enum or struct definition
parse_missing_expression_in_for_loop = missing expression to iterate on in `for` loop parse_missing_expression_in_for_loop = missing expression to iterate on in `for` loop
.suggestion = try adding an expression to the `for` loop .suggestion = try adding an expression to the `for` loop
parse_missing_fn_for_function_definition = missing `fn` for function definition parse_missing_fn_for_function_definition = missing `fn` for function definition
.suggestion = add `fn` here to parse `{$ident}` as a public function .suggestion = add `fn` here to parse `{$ident}` as a function
parse_missing_fn_for_method_definition = missing `fn` for method definition parse_missing_fn_for_method_definition = missing `fn` for method definition
.suggestion = add `fn` here to parse `{$ident}` as a public method .suggestion = add `fn` here to parse `{$ident}` as a method
parse_missing_fn_or_struct_for_item_definition = missing `fn` or `struct` for function or struct definition
.suggestion = if you meant to call a macro, try
.help = if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier
parse_missing_fn_params = missing parameters for function definition parse_missing_fn_params = missing parameters for function definition
.suggestion = add a parameter list .suggestion = add a parameter list
@ -555,7 +560,7 @@ parse_missing_semicolon_before_array = expected `;`, found `[`
.suggestion = consider adding `;` here .suggestion = consider adding `;` here
parse_missing_struct_for_struct_definition = missing `struct` for struct definition parse_missing_struct_for_struct_definition = missing `struct` for struct definition
.suggestion = add `struct` here to parse `{$ident}` as a public struct .suggestion = add `struct` here to parse `{$ident}` as a struct
parse_missing_trait_in_trait_impl = missing trait in a trait impl parse_missing_trait_in_trait_impl = missing trait in a trait impl
.suggestion_add_trait = add a trait here .suggestion_add_trait = add a trait here

View File

@ -1612,28 +1612,44 @@ pub(crate) struct DefaultNotFollowedByItem {
#[derive(Diagnostic)] #[derive(Diagnostic)]
pub(crate) enum MissingKeywordForItemDefinition { pub(crate) enum MissingKeywordForItemDefinition {
#[diag(parse_missing_enum_for_enum_definition)]
Enum {
#[primary_span]
span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "enum ")]
insert_span: Span,
ident: Ident,
},
#[diag(parse_missing_enum_or_struct_for_item_definition)]
EnumOrStruct {
#[primary_span]
span: Span,
},
#[diag(parse_missing_struct_for_struct_definition)] #[diag(parse_missing_struct_for_struct_definition)]
Struct { Struct {
#[primary_span] #[primary_span]
#[suggestion(style = "short", applicability = "maybe-incorrect", code = " struct ")]
span: Span, span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "struct ")]
insert_span: Span,
ident: Ident, ident: Ident,
}, },
#[diag(parse_missing_fn_for_function_definition)] #[diag(parse_missing_fn_for_function_definition)]
Function { Function {
#[primary_span] #[primary_span]
#[suggestion(style = "short", applicability = "maybe-incorrect", code = " fn ")]
span: Span, span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "fn ")]
insert_span: Span,
ident: Ident, ident: Ident,
}, },
#[diag(parse_missing_fn_for_method_definition)] #[diag(parse_missing_fn_for_method_definition)]
Method { Method {
#[primary_span] #[primary_span]
#[suggestion(style = "short", applicability = "maybe-incorrect", code = " fn ")]
span: Span, span: Span,
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "fn ")]
insert_span: Span,
ident: Ident, ident: Ident,
}, },
#[diag(parse_ambiguous_missing_keyword_for_item_definition)] #[diag(parse_missing_fn_or_struct_for_item_definition)]
Ambiguous { Ambiguous {
#[primary_span] #[primary_span]
span: Span, span: Span,
@ -1644,7 +1660,12 @@ pub(crate) enum MissingKeywordForItemDefinition {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum AmbiguousMissingKwForItemSub { pub(crate) enum AmbiguousMissingKwForItemSub {
#[suggestion(parse_suggestion, applicability = "maybe-incorrect", code = "{snippet}!")] #[suggestion(
parse_suggestion,
style = "verbose",
applicability = "maybe-incorrect",
code = "{snippet}!"
)]
SuggestMacro { SuggestMacro {
#[primary_span] #[primary_span]
span: Span, span: Span,

View File

@ -239,6 +239,7 @@ impl<'a> Parser<'a> {
self.recover_const_impl(const_span, attrs, def_())? self.recover_const_impl(const_span, attrs, def_())?
} else { } else {
self.recover_const_mut(const_span); self.recover_const_mut(const_span);
self.recover_missing_kw_before_item()?;
let (ident, generics, ty, expr) = self.parse_const_item()?; let (ident, generics, ty, expr) = self.parse_const_item()?;
( (
ident, ident,
@ -311,6 +312,9 @@ impl<'a> Parser<'a> {
Case::Insensitive, Case::Insensitive,
); );
} else if macros_allowed && self.check_path() { } else if macros_allowed && self.check_path() {
if self.isnt_macro_invocation() {
self.recover_missing_kw_before_item()?;
}
// MACRO INVOCATION ITEM // MACRO INVOCATION ITEM
(Ident::empty(), ItemKind::MacCall(P(self.parse_item_macro(vis)?))) (Ident::empty(), ItemKind::MacCall(P(self.parse_item_macro(vis)?)))
} else { } else {
@ -374,25 +378,25 @@ impl<'a> Parser<'a> {
self.check_ident() && self.look_ahead(1, |t| *t != token::Not && *t != token::PathSep) self.check_ident() && self.look_ahead(1, |t| *t != token::Not && *t != token::PathSep)
} }
/// Recover on encountering a struct or method definition where the user /// Recover on encountering a struct, enum, or method definition where the user
/// forgot to add the `struct` or `fn` keyword after writing `pub`: `pub S {}`. /// forgot to add the `struct`, `enum`, or `fn` keyword
fn recover_missing_kw_before_item(&mut self) -> PResult<'a, ()> { fn recover_missing_kw_before_item(&mut self) -> PResult<'a, ()> {
// Space between `pub` keyword and the identifier let is_pub = self.prev_token.is_keyword(kw::Pub);
// let is_const = self.prev_token.is_keyword(kw::Const);
// pub S {} let ident_span = self.token.span;
// ^^^ `sp` points here let span = if is_pub { self.prev_token.span.to(ident_span) } else { ident_span };
let sp = self.prev_token.span.between(self.token.span); let insert_span = ident_span.shrink_to_lo();
let full_sp = self.prev_token.span.to(self.token.span);
let ident_sp = self.token.span;
let ident = if self.look_ahead(1, |t| { let ident = if (!is_const
[ || self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Parenthesis)))
token::Lt, && self.look_ahead(1, |t| {
token::OpenDelim(Delimiter::Brace), [
token::OpenDelim(Delimiter::Parenthesis), token::Lt,
] token::OpenDelim(Delimiter::Brace),
.contains(&t.kind) token::OpenDelim(Delimiter::Parenthesis),
}) { ]
.contains(&t.kind)
}) {
self.parse_ident().unwrap() self.parse_ident().unwrap()
} else { } else {
return Ok(()); return Ok(());
@ -406,46 +410,56 @@ impl<'a> Parser<'a> {
} }
let err = if self.check(&token::OpenDelim(Delimiter::Brace)) { let err = if self.check(&token::OpenDelim(Delimiter::Brace)) {
// possible public struct definition where `struct` was forgotten // possible struct or enum definition where `struct` or `enum` was forgotten
Some(errors::MissingKeywordForItemDefinition::Struct { span: sp, ident }) if self.look_ahead(1, |t| *t == token::CloseDelim(Delimiter::Brace)) {
// `S {}` could be unit enum or struct
Some(errors::MissingKeywordForItemDefinition::EnumOrStruct { span })
} else if self.look_ahead(2, |t| *t == token::Colon)
|| self.look_ahead(3, |t| *t == token::Colon)
{
// `S { f:` or `S { pub f:`
Some(errors::MissingKeywordForItemDefinition::Struct { span, insert_span, ident })
} else {
Some(errors::MissingKeywordForItemDefinition::Enum { span, insert_span, ident })
}
} else if self.check(&token::OpenDelim(Delimiter::Parenthesis)) { } else if self.check(&token::OpenDelim(Delimiter::Parenthesis)) {
// possible public function or tuple struct definition where `fn`/`struct` was // possible function or tuple struct definition where `fn` or `struct` was forgotten
// forgotten
self.bump(); // `(` self.bump(); // `(`
let is_method = self.recover_self_param(); let is_method = self.recover_self_param();
self.consume_block(Delimiter::Parenthesis, ConsumeClosingDelim::Yes); self.consume_block(Delimiter::Parenthesis, ConsumeClosingDelim::Yes);
let err = let err = if self.check(&token::RArrow)
if self.check(&token::RArrow) || self.check(&token::OpenDelim(Delimiter::Brace)) { || self.check(&token::OpenDelim(Delimiter::Brace))
self.eat_to_tokens(&[&token::OpenDelim(Delimiter::Brace)]); {
self.bump(); // `{` self.eat_to_tokens(&[&token::OpenDelim(Delimiter::Brace)]);
self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes); self.bump(); // `{`
if is_method { self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
errors::MissingKeywordForItemDefinition::Method { span: sp, ident } if is_method {
} else { errors::MissingKeywordForItemDefinition::Method { span, insert_span, ident }
errors::MissingKeywordForItemDefinition::Function { span: sp, ident }
}
} else if self.check(&token::Semi) {
errors::MissingKeywordForItemDefinition::Struct { span: sp, ident }
} else { } else {
errors::MissingKeywordForItemDefinition::Ambiguous { errors::MissingKeywordForItemDefinition::Function { span, insert_span, ident }
span: sp, }
subdiag: if found_generics { } else if is_pub && self.check(&token::Semi) {
None errors::MissingKeywordForItemDefinition::Struct { span, insert_span, ident }
} else if let Ok(snippet) = self.span_to_snippet(ident_sp) { } else {
Some(errors::AmbiguousMissingKwForItemSub::SuggestMacro { errors::MissingKeywordForItemDefinition::Ambiguous {
span: full_sp, span,
snippet, subdiag: if found_generics {
}) None
} else { } else if let Ok(snippet) = self.span_to_snippet(ident_span) {
Some(errors::AmbiguousMissingKwForItemSub::HelpMacro) Some(errors::AmbiguousMissingKwForItemSub::SuggestMacro {
}, span: ident_span,
} snippet,
}; })
} else {
Some(errors::AmbiguousMissingKwForItemSub::HelpMacro)
},
}
};
Some(err) Some(err)
} else if found_generics { } else if found_generics {
Some(errors::MissingKeywordForItemDefinition::Ambiguous { span: sp, subdiag: None }) Some(errors::MissingKeywordForItemDefinition::Ambiguous { span, subdiag: None })
} else { } else {
None None
}; };

View File

@ -5,7 +5,7 @@ impl dyn A {
struct S; struct S;
trait X { trait X {
X() {} //~ ERROR expected one of `!` or `::`, found `(` X() {} //~ ERROR missing `fn` for function definition
fn xxx() { ### } fn xxx() { ### }
L = M; L = M;
Z = { 2 + 3 }; Z = { 2 + 3 };
@ -13,7 +13,7 @@ trait X {
} }
trait A { trait A {
X() {} //~ ERROR expected one of `!` or `::`, found `(` X() {} //~ ERROR missing `fn` for function definition
} }
trait B { trait B {
fn xxx() { ### } //~ ERROR expected fn xxx() { ### } //~ ERROR expected

View File

@ -11,26 +11,36 @@ LL | }
| unexpected token | unexpected token
| the item list ends here | the item list ends here
error: expected one of `!` or `::`, found `(` error: missing `fn` for function definition
--> $DIR/issue-40006.rs:8:6 --> $DIR/issue-40006.rs:8:5
| |
LL | trait X { LL | trait X {
| - while parsing this item list starting here | - while parsing this item list starting here
LL | X() {} LL | X() {}
| ^ expected one of `!` or `::` | ^
... ...
LL | } LL | }
| - the item list ends here | - the item list ends here
|
help: add `fn` here to parse `X` as a function
|
LL | fn X() {}
| ++
error: expected one of `!` or `::`, found `(` error: missing `fn` for function definition
--> $DIR/issue-40006.rs:16:6 --> $DIR/issue-40006.rs:16:5
| |
LL | trait A { LL | trait A {
| - while parsing this item list starting here | - while parsing this item list starting here
LL | X() {} LL | X() {}
| ^ expected one of `!` or `::` | ^
LL | } LL | }
| - the item list ends here | - the item list ends here
|
help: add `fn` here to parse `X` as a function
|
LL | fn X() {}
| ++
error: expected one of `!` or `[`, found `#` error: expected one of `!` or `[`, found `#`
--> $DIR/issue-40006.rs:19:17 --> $DIR/issue-40006.rs:19:17
@ -69,17 +79,17 @@ LL | }
| - the item list ends here | - the item list ends here
error: missing `fn` for method definition error: missing `fn` for method definition
--> $DIR/issue-40006.rs:32:8 --> $DIR/issue-40006.rs:32:5
| |
LL | impl S { LL | impl S {
| - while parsing this item list starting here | - while parsing this item list starting here
LL | pub hello_method(&self) { LL | pub hello_method(&self) {
| ^ | ^^^^^^^^^^^^^^^^
... ...
LL | } LL | }
| - the item list ends here | - the item list ends here
| |
help: add `fn` here to parse `hello_method` as a public method help: add `fn` here to parse `hello_method` as a method
| |
LL | pub fn hello_method(&self) { LL | pub fn hello_method(&self) {
| ++ | ++

View File

@ -10,6 +10,6 @@ pub fn foo() -> Foo {
pub Foo { text } pub Foo { text }
} }
//~^^ ERROR missing `struct` for struct definition //~^^ ERROR missing `enum` for enum definition
fn main() {} fn main() {}

View File

@ -1,13 +1,13 @@
error: missing `struct` for struct definition error: missing `enum` for enum definition
--> $DIR/recovered-block.rs:11:8 --> $DIR/recovered-block.rs:11:5
| |
LL | pub Foo { text } LL | pub Foo { text }
| ^ | ^^^^^^^
| |
help: add `struct` here to parse `Foo` as a public struct help: add `enum` here to parse `Foo` as an enum
| |
LL | pub struct Foo { text } LL | pub enum Foo { text }
| ++++++ | ++++
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,5 +1,7 @@
extern "C" { extern "C" {
f(); //~ ERROR expected one of `!` or `::`, found `(` f();
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~| HELP if you meant to call a macro, try
} }
fn main() { fn main() {

View File

@ -1,12 +1,18 @@
error: expected one of `!` or `::`, found `(` error: missing `fn` or `struct` for function or struct definition
--> $DIR/extern-no-fn.rs:2:6 --> $DIR/extern-no-fn.rs:2:5
| |
LL | extern "C" { LL | extern "C" {
| - while parsing this item list starting here | - while parsing this item list starting here
LL | f(); LL | f();
| ^ expected one of `!` or `::` | ^
...
LL | } LL | }
| - the item list ends here | - the item list ends here
|
help: if you meant to call a macro, try
|
LL | f!();
| ~~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -0,0 +1,6 @@
Whoops {
//~^ ERROR missing `enum` for enum definition
//~| HELP add `enum` here to parse `Whoops` as an enum
OptionA,
OptionB,
}

View File

@ -0,0 +1,13 @@
error: missing `enum` for enum definition
--> $DIR/missing-enum-issue-125446.rs:1:1
|
LL | Whoops {
| ^^^^^^
|
help: add `enum` here to parse `Whoops` as an enum
|
LL | enum Whoops {
| ++++
error: aborting due to 1 previous error

View File

@ -0,0 +1,2 @@
Whoops {}
//~^ ERROR missing `enum` or `struct` for enum or struct definition

View File

@ -0,0 +1,8 @@
error: missing `enum` or `struct` for enum or struct definition
--> $DIR/missing-enum-or-struct-issue-125446.rs:1:1
|
LL | Whoops {}
| ^^^^^^
error: aborting due to 1 previous error

View File

@ -0,0 +1,7 @@
whoops() {}
//~^ ERROR missing `fn` for function definition
//~| HELP add `fn` here to parse `whoops` as a function
fn main() {
whoops();
}

View File

@ -0,0 +1,13 @@
error: missing `fn` for function definition
--> $DIR/missing-fn-issue-125446.rs:1:1
|
LL | whoops() {}
| ^^^^^^
|
help: add `fn` here to parse `whoops` as a function
|
LL | fn whoops() {}
| ++
error: aborting due to 1 previous error

View File

@ -0,0 +1,4 @@
main() {
//~^ ERROR missing `fn` for function definition
//~| HELP add `fn` here to parse `main` as a function
}

View File

@ -0,0 +1,13 @@
error: missing `fn` for function definition
--> $DIR/missing-fn-issue-65381-1.rs:1:1
|
LL | main() {
| ^^^^
|
help: add `fn` here to parse `main` as a function
|
LL | fn main() {
| ++
error: aborting due to 1 previous error

View File

@ -0,0 +1,3 @@
main();
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~| HELP if you meant to call a macro, try

View File

@ -0,0 +1,13 @@
error: missing `fn` or `struct` for function or struct definition
--> $DIR/missing-fn-issue-65381-2.rs:1:1
|
LL | main();
| ^^^^
|
help: if you meant to call a macro, try
|
LL | main!();
| ~~~~~
error: aborting due to 1 previous error

View File

@ -0,0 +1,4 @@
pub const initial_value() -> Self {
//~^ ERROR missing `fn` for function definition
//~| HELP add `fn` here to parse `initial_value` as a function
}

View File

@ -0,0 +1,13 @@
error: missing `fn` for function definition
--> $DIR/missing-fn-issue-65381-3.rs:1:11
|
LL | pub const initial_value() -> Self {
| ^^^^^^^^^^^^^
|
help: add `fn` here to parse `initial_value` as a function
|
LL | pub const fn initial_value() -> Self {
| ++
error: aborting due to 1 previous error

View File

@ -0,0 +1,5 @@
Whoops {
//~^ ERROR missing `struct` for struct definition
//~| HELP add `struct` here to parse `Whoops` as a struct
value: u64,
}

View File

@ -0,0 +1,13 @@
error: missing `struct` for struct definition
--> $DIR/missing-struct-issue-125446.rs:1:1
|
LL | Whoops {
| ^^^^^^
|
help: add `struct` here to parse `Whoops` as a struct
|
LL | struct Whoops {
| ++++++
error: aborting due to 1 previous error

View File

@ -1,10 +1,10 @@
error: missing `fn` for function definition error: missing `fn` for function definition
--> $DIR/pub-ident-fn-2.rs:3:4 --> $DIR/pub-ident-fn-2.rs:3:1
| |
LL | pub foo(_s: usize) { bar() } LL | pub foo(_s: usize) { bar() }
| ^ | ^^^^^^^
| |
help: add `fn` here to parse `foo` as a public function help: add `fn` here to parse `foo` as a function
| |
LL | pub fn foo(_s: usize) { bar() } LL | pub fn foo(_s: usize) { bar() }
| ++ | ++

View File

@ -1,8 +1,13 @@
error: missing `fn` or `struct` for function or struct definition error: missing `fn` or `struct` for function or struct definition
--> $DIR/pub-ident-fn-or-struct.rs:1:4 --> $DIR/pub-ident-fn-or-struct.rs:1:1
| |
LL | pub S (foo) bar LL | pub S (foo) bar
| ---^- help: if you meant to call a macro, try: `S!` | ^^^^^
|
help: if you meant to call a macro, try
|
LL | pub S! (foo) bar
| ~~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,4 +1,4 @@
pub bar<'a>(&self, _s: &'a usize) -> bool { true } pub bar<'a>(&self, _s: &'a usize) -> bool { true }
//~^ ERROR missing `fn` for method definition //~^ ERROR missing `fn` for method definition
fn main() { fn main() {

View File

@ -1,10 +1,10 @@
error: missing `fn` for method definition error: missing `fn` for method definition
--> $DIR/pub-ident-fn-with-lifetime-2.rs:1:4 --> $DIR/pub-ident-fn-with-lifetime-2.rs:1:1
| |
LL | pub bar<'a>(&self, _s: &'a usize) -> bool { true } LL | pub bar<'a>(&self, _s: &'a usize) -> bool { true }
| ^^^ | ^^^^^^^
| |
help: add `fn` here to parse `bar` as a public method help: add `fn` here to parse `bar` as a method
| |
LL | pub fn bar<'a>(&self, _s: &'a usize) -> bool { true } LL | pub fn bar<'a>(&self, _s: &'a usize) -> bool { true }
| ++ | ++

View File

@ -1,6 +1,6 @@
//@ run-rustfix //@ run-rustfix
pub foo<'a>(_s: &'a usize) -> bool { true } pub foo<'a>(_s: &'a usize) -> bool { true }
//~^ ERROR missing `fn` for function definition //~^ ERROR missing `fn` for function definition
fn main() { fn main() {

View File

@ -1,10 +1,10 @@
error: missing `fn` for function definition error: missing `fn` for function definition
--> $DIR/pub-ident-fn-with-lifetime.rs:3:4 --> $DIR/pub-ident-fn-with-lifetime.rs:3:1
| |
LL | pub foo<'a>(_s: &'a usize) -> bool { true } LL | pub foo<'a>(_s: &'a usize) -> bool { true }
| ^^^ | ^^^^^^^
| |
help: add `fn` here to parse `foo` as a public function help: add `fn` here to parse `foo` as a function
| |
LL | pub fn foo<'a>(_s: &'a usize) -> bool { true } LL | pub fn foo<'a>(_s: &'a usize) -> bool { true }
| ++ | ++

View File

@ -1,6 +1,6 @@
//@ run-rustfix //@ run-rustfix
pub foo(_s: usize) -> bool { true } pub foo(_s: usize) -> bool { true }
//~^ ERROR missing `fn` for function definition //~^ ERROR missing `fn` for function definition
fn main() { fn main() {

View File

@ -1,10 +1,10 @@
error: missing `fn` for function definition error: missing `fn` for function definition
--> $DIR/pub-ident-fn.rs:3:4 --> $DIR/pub-ident-fn.rs:3:1
| |
LL | pub foo(_s: usize) -> bool { true } LL | pub foo(_s: usize) -> bool { true }
| ^^^ | ^^^^^^^
| |
help: add `fn` here to parse `foo` as a public function help: add `fn` here to parse `foo` as a function
| |
LL | pub fn foo(_s: usize) -> bool { true } LL | pub fn foo(_s: usize) -> bool { true }
| ++ | ++

View File

@ -1,10 +1,10 @@
error: missing `struct` for struct definition error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-2.rs:4:8 --> $DIR/pub-ident-struct-2.rs:4:5
| |
LL | pub bar(); LL | pub bar();
| ^ | ^^^^^^^
| |
help: add `struct` here to parse `bar` as a public struct help: add `struct` here to parse `bar` as a struct
| |
LL | pub struct bar(); LL | pub struct bar();
| ++++++ | ++++++

View File

@ -1,10 +1,10 @@
error: missing `struct` for struct definition error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-3.rs:1:4 --> $DIR/pub-ident-struct-3.rs:1:1
| |
LL | pub S(); LL | pub S();
| ^ | ^^^^^
| |
help: add `struct` here to parse `S` as a public struct help: add `struct` here to parse `S` as a struct
| |
LL | pub struct S(); LL | pub struct S();
| ++++++ | ++++++

View File

@ -1,10 +1,10 @@
error: missing `struct` for struct definition error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-4.rs:4:4 --> $DIR/pub-ident-struct-4.rs:4:1
| |
LL | pub T(String); LL | pub T(String);
| ^ | ^^^^^
| |
help: add `struct` here to parse `T` as a public struct help: add `struct` here to parse `T` as a struct
| |
LL | pub struct T(String); LL | pub struct T(String);
| ++++++ | ++++++

View File

@ -1,4 +1,4 @@
pub S<'a> { pub S<'a> {
//~^ ERROR missing `struct` for struct definition //~^ ERROR missing `enum` or `struct` for enum or struct definition
} }
fn main() {} fn main() {}

View File

@ -1,13 +1,8 @@
error: missing `struct` for struct definition error: missing `enum` or `struct` for enum or struct definition
--> $DIR/pub-ident-struct-with-lifetime.rs:1:4 --> $DIR/pub-ident-struct-with-lifetime.rs:1:1
| |
LL | pub S<'a> { LL | pub S<'a> {
| ^ | ^^^^^
|
help: add `struct` here to parse `S` as a public struct
|
LL | pub struct S<'a> {
| ++++++
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,6 +0,0 @@
//@ run-rustfix
pub struct S {
//~^ ERROR missing `struct` for struct definition
}
fn main() {}

View File

@ -1,6 +1,4 @@
//@ run-rustfix
pub S { pub S {
//~^ ERROR missing `struct` for struct definition //~^ ERROR missing `enum` or `struct` for enum or struct definition
} }
fn main() {} fn main() {}

View File

@ -1,13 +1,8 @@
error: missing `struct` for struct definition error: missing `enum` or `struct` for enum or struct definition
--> $DIR/pub-ident-struct.rs:3:4 --> $DIR/pub-ident-struct.rs:1:1
| |
LL | pub S { LL | pub S {
| ^ | ^^^^^
|
help: add `struct` here to parse `S` as a public struct
|
LL | pub struct S {
| ++++++
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,5 +1,5 @@
fn main() { fn main() {
} }
pub foo<'a> pub foo<'a>
//~^ ERROR missing `fn` or `struct` for function or struct definition //~^ ERROR missing `fn` or `struct` for function or struct definition

View File

@ -1,8 +1,8 @@
error: missing `fn` or `struct` for function or struct definition error: missing `fn` or `struct` for function or struct definition
--> $DIR/pub-ident-with-lifetime-incomplete.rs:4:4 --> $DIR/pub-ident-with-lifetime-incomplete.rs:4:1
| |
LL | pub foo<'a> LL | pub foo<'a>
| ^^^ | ^^^^^^^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -1,14 +1,14 @@
error: missing `struct` for struct definition error: missing `enum` for enum definition
--> $DIR/track4.rs:LL:CC --> $DIR/track4.rs:LL:CC
| |
LL | pub onion { LL | pub onion {
| ^ | ^^^^^^^^^
-Ztrack-diagnostics: created at compiler/rustc_parse/src/parser/item.rs:LL:CC -Ztrack-diagnostics: created at compiler/rustc_parse/src/parser/item.rs:LL:CC
| |
help: add `struct` here to parse `onion` as a public struct help: add `enum` here to parse `onion` as an enum
| |
LL | pub struct onion { LL | pub enum onion {
| ++++++ | ++++
error: aborting due to 1 previous error error: aborting due to 1 previous error