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

This commit is contained in:
trevyn 2024-07-06 13:14:53 +03:00
parent 51917e2e69
commit b40adc9d3b
42 changed files with 308 additions and 146 deletions

View file

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

View file

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

View file

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

View file

@ -1,13 +1,13 @@
error: missing `struct` for struct definition
--> $DIR/recovered-block.rs:11:8
error: missing `enum` for enum definition
--> $DIR/recovered-block.rs:11:5
|
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

View file

@ -1,5 +1,7 @@
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() {

View file

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

View file

@ -1,8 +1,13 @@
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
| ---^- 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

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
fn main() {

View file

@ -1,10 +1,10 @@
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 }
| ++

View file

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

View file

@ -1,10 +1,10 @@
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 }
| ++

View file

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

View file

@ -1,10 +1,10 @@
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 }
| ++

View file

@ -1,10 +1,10 @@
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();
| ^
| ^^^^^^^
|
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();
| ++++++

View file

@ -1,10 +1,10 @@
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();
| ^
| ^^^^^
|
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();
| ++++++

View file

@ -1,10 +1,10 @@
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);
| ^
| ^^^^^
|
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);
| ++++++

View file

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

View file

@ -1,13 +1,8 @@
error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-with-lifetime.rs:1:4
error: missing `enum` or `struct` for enum or struct definition
--> $DIR/pub-ident-struct-with-lifetime.rs:1:1
|
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

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 {
//~^ ERROR missing `struct` for struct definition
//~^ ERROR missing `enum` or `struct` for enum or struct definition
}
fn main() {}

View file

@ -1,13 +1,8 @@
error: missing `struct` for struct definition
--> $DIR/pub-ident-struct.rs:3:4
error: missing `enum` or `struct` for enum or struct definition
--> $DIR/pub-ident-struct.rs:1:1
|
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

View file

@ -1,5 +1,5 @@
fn main() {
}
pub foo<'a>
pub foo<'a>
//~^ 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
--> $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

View file

@ -1,14 +1,14 @@
error: missing `struct` for struct definition
error: missing `enum` for enum definition
--> $DIR/track4.rs:LL:CC
|
LL | pub onion {
| ^
| ^^^^^^^^^
-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