Skip to content

Commit f94a148

Browse files
committed
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(...);
1 parent 27c0c46 commit f94a148

File tree

8 files changed

+44
-9
lines changed

8 files changed

+44
-9
lines changed

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'a> Parser<'a> {
412412
} else if self.check(&token::OpenDelim(Delimiter::Brace)) {
413413
self.bump(); // `{`
414414
("fn", kw_name, false)
415-
} else if self.check(&token::Colon) {
415+
} else if self.check(&token::Semi) {
416416
let kw = "struct";
417417
(kw, kw, false)
418418
} else {

src/test/ui/pub/pub-ident-fn-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod foo {
44
pub bar();
5-
//~^ ERROR missing `fn` or `struct` for function or struct definition
5+
//~^ ERROR missing `struct` for struct definition
66
}
77

88
fn main() {}

src/test/ui/pub/pub-ident-fn-3.stderr

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
error: missing `fn` or `struct` for function or struct definition
2-
--> $DIR/pub-ident-fn-3.rs:4:8
1+
error: missing `struct` for struct definition
2+
--> $DIR/pub-ident-struct-2.rs:4:8
33
|
44
LL | pub bar();
5-
| ---^--- help: if you meant to call a macro, try: `bar!`
5+
| ^
6+
|
7+
help: add `struct` here to parse `bar` as a public struct
8+
|
9+
LL | pub struct bar();
10+
| ++++++
611

712
error: aborting due to previous error
813

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub S();
2-
//~^ ERROR missing `fn` or `struct` for function or struct definition
2+
//~^ ERROR missing `struct` for struct definition
33

44
fn main() {}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
error: missing `fn` or `struct` for function or struct definition
2-
--> $DIR/pub-ident-fn-or-struct-2.rs:1:4
1+
error: missing `struct` for struct definition
2+
--> $DIR/pub-ident-struct-3.rs:1:4
33
|
44
LL | pub S();
5-
| ---^- help: if you meant to call a macro, try: `S!`
5+
| ^
6+
|
7+
help: add `struct` here to parse `S` as a public struct
8+
|
9+
LL | pub struct S();
10+
| ++++++
611

712
error: aborting due to previous error
813

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-rustfix
2+
3+
pub struct T(String);
4+
//~^ ERROR missing `struct` for struct definition
5+
6+
fn main() {}

src/test/ui/pub/pub-ident-struct-4.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-rustfix
2+
3+
pub T(String);
4+
//~^ ERROR missing `struct` for struct definition
5+
6+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: missing `struct` for struct definition
2+
--> $DIR/pub-ident-struct-4.rs:3:4
3+
|
4+
LL | pub T(String);
5+
| ^
6+
|
7+
help: add `struct` here to parse `T` as a public struct
8+
|
9+
LL | pub struct T(String);
10+
| ++++++
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)