about summary refs log tree commit diff
diff options
context:
space:
mode:
authorXiretza <xiretza@xiretza.xyz>2022-10-06 18:35:53 +0200
committerXiretza <xiretza@xiretza.xyz>2023-02-01 21:50:34 +0100
commit0757d5f83f4bc4faca896c85932cf1e4a0cd6031 (patch)
treea10dccb1ef78f9869c3fdcc87a647023cfa9a787
parenta84adba55239b5bfa702ee4937a7f14b36aab181 (diff)
downloadrust-0757d5f83f4bc4faca896c85932cf1e4a0cd6031.tar.gz
rust-0757d5f83f4bc4faca896c85932cf1e4a0cd6031.zip
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(...);
-rw-r--r--compiler/rustc_parse/src/parser/item.rs2
-rw-r--r--tests/ui/pub/pub-ident-fn-3.rs2
-rw-r--r--tests/ui/pub/pub-ident-fn-3.stderr9
-rw-r--r--tests/ui/pub/pub-ident-fn-or-struct-2.rs2
-rw-r--r--tests/ui/pub/pub-ident-fn-or-struct-2.stderr9
-rw-r--r--tests/ui/pub/pub-ident-struct-4.fixed6
-rw-r--r--tests/ui/pub/pub-ident-struct-4.rs6
-rw-r--r--tests/ui/pub/pub-ident-struct-4.stderr13
8 files changed, 42 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index d72c7d8cabc..32ffc9306f2 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -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 {
diff --git a/tests/ui/pub/pub-ident-fn-3.rs b/tests/ui/pub/pub-ident-fn-3.rs
index fdbea7cf487..50db4039d4f 100644
--- a/tests/ui/pub/pub-ident-fn-3.rs
+++ b/tests/ui/pub/pub-ident-fn-3.rs
@@ -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() {}
diff --git a/tests/ui/pub/pub-ident-fn-3.stderr b/tests/ui/pub/pub-ident-fn-3.stderr
index 6d3d4e592c8..23eadec1193 100644
--- a/tests/ui/pub/pub-ident-fn-3.stderr
+++ b/tests/ui/pub/pub-ident-fn-3.stderr
@@ -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
 
diff --git a/tests/ui/pub/pub-ident-fn-or-struct-2.rs b/tests/ui/pub/pub-ident-fn-or-struct-2.rs
index 8f67cdd2933..dfa6cf2ee1e 100644
--- a/tests/ui/pub/pub-ident-fn-or-struct-2.rs
+++ b/tests/ui/pub/pub-ident-fn-or-struct-2.rs
@@ -1,4 +1,4 @@
 pub S();
-//~^ ERROR missing `fn` or `struct` for function or struct definition
+//~^ ERROR missing `struct` for struct definition
 
 fn main() {}
diff --git a/tests/ui/pub/pub-ident-fn-or-struct-2.stderr b/tests/ui/pub/pub-ident-fn-or-struct-2.stderr
index 047e66b18d8..b7a9bc0a7db 100644
--- a/tests/ui/pub/pub-ident-fn-or-struct-2.stderr
+++ b/tests/ui/pub/pub-ident-fn-or-struct-2.stderr
@@ -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
 
diff --git a/tests/ui/pub/pub-ident-struct-4.fixed b/tests/ui/pub/pub-ident-struct-4.fixed
new file mode 100644
index 00000000000..b49fa678e1b
--- /dev/null
+++ b/tests/ui/pub/pub-ident-struct-4.fixed
@@ -0,0 +1,6 @@
+// run-rustfix
+
+pub struct T(String);
+//~^ ERROR missing `struct` for struct definition
+
+fn main() {}
diff --git a/tests/ui/pub/pub-ident-struct-4.rs b/tests/ui/pub/pub-ident-struct-4.rs
new file mode 100644
index 00000000000..20bc94b0acb
--- /dev/null
+++ b/tests/ui/pub/pub-ident-struct-4.rs
@@ -0,0 +1,6 @@
+// run-rustfix
+
+pub T(String);
+//~^ ERROR missing `struct` for struct definition
+
+fn main() {}
diff --git a/tests/ui/pub/pub-ident-struct-4.stderr b/tests/ui/pub/pub-ident-struct-4.stderr
new file mode 100644
index 00000000000..90c7138e5ce
--- /dev/null
+++ b/tests/ui/pub/pub-ident-struct-4.stderr
@@ -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
+