Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix condition for "missing struct" diagnostic on tuple structs
The check previously matched this, and suggested adding a missing
`struct`:

pub Foo(...):

It was probably intended to match this instead (semicolon instead of
colon):

pub Foo(...);
  • Loading branch information
Xiretza committed Feb 1, 2023
commit 0757d5f83f4bc4faca896c85932cf1e4a0cd6031
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl<'a> Parser<'a> {
} else if self.check(&token::OpenDelim(Delimiter::Brace)) {
self.bump(); // `{`
("fn", kw_name, false)
} else if self.check(&token::Colon) {
} else if self.check(&token::Semi) {
let kw = "struct";
(kw, kw, false)
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pub/pub-ident-fn-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod foo {
pub bar();
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~^ ERROR missing `struct` for struct definition
}

fn main() {}
9 changes: 7 additions & 2 deletions tests/ui/pub/pub-ident-fn-3.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: missing `fn` or `struct` for function or struct definition
error: missing `struct` for struct definition
--> $DIR/pub-ident-fn-3.rs:4:8
|
LL | pub bar();
| ---^--- help: if you meant to call a macro, try: `bar!`
| ^
|
help: add `struct` here to parse `bar` as a public struct
|
LL | pub struct bar();
| ++++++

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/pub/pub-ident-fn-or-struct-2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub S();
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~^ ERROR missing `struct` for struct definition

fn main() {}
9 changes: 7 additions & 2 deletions tests/ui/pub/pub-ident-fn-or-struct-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: missing `fn` or `struct` for function or struct definition
error: missing `struct` for struct definition
--> $DIR/pub-ident-fn-or-struct-2.rs:1:4
|
LL | pub S();
| ---^- help: if you meant to call a macro, try: `S!`
| ^
|
help: add `struct` here to parse `S` as a public struct
|
LL | pub struct S();
| ++++++

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/pub/pub-ident-struct-4.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-rustfix

pub struct T(String);
//~^ ERROR missing `struct` for struct definition

fn main() {}
6 changes: 6 additions & 0 deletions tests/ui/pub/pub-ident-struct-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-rustfix

pub T(String);
//~^ ERROR missing `struct` for struct definition

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/pub/pub-ident-struct-4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-4.rs:3:4
|
LL | pub T(String);
| ^
|
help: add `struct` here to parse `T` as a public struct
|
LL | pub struct T(String);
| ++++++

error: aborting due to previous error