about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-04-19 11:04:41 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-04-19 11:04:41 -0700
commit30b779f3984fa41a54f30c78bd4559233b4e3c4a (patch)
tree564c09aed9a49cb384fe1a6130aebe48eeaa4bd0 /src
parenta2bbf7debaab60be33bd8008a71bca69576945a0 (diff)
downloadrust-30b779f3984fa41a54f30c78bd4559233b4e3c4a.tar.gz
rust-30b779f3984fa41a54f30c78bd4559233b4e3c4a.zip
Remove assumption from recovery code
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/parser.rs2
-rw-r--r--src/test/ui/pub/pub-ident-fn-3.rs8
-rw-r--r--src/test/ui/pub/pub-ident-fn-3.stderr8
3 files changed, 17 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a5adb37f745..cc854e938ff 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -8366,11 +8366,11 @@ impl<'a> Parser<'a> {
                 } else {
                     ("fn` or `struct", "function or struct", true)
                 };
-                self.consume_block(token::Brace);
 
                 let msg = format!("missing `{}` for {} definition", kw, kw_name);
                 let mut err = self.diagnostic().struct_span_err(sp, &msg);
                 if !ambiguous {
+                    self.consume_block(token::Brace);
                     let suggestion = format!("add `{}` here to parse `{}` as a public {}",
                                              kw,
                                              ident,
diff --git a/src/test/ui/pub/pub-ident-fn-3.rs b/src/test/ui/pub/pub-ident-fn-3.rs
new file mode 100644
index 00000000000..fdbea7cf487
--- /dev/null
+++ b/src/test/ui/pub/pub-ident-fn-3.rs
@@ -0,0 +1,8 @@
+// #60115
+
+mod foo {
+    pub bar();
+    //~^ ERROR missing `fn` or `struct` for function or struct definition
+}
+
+fn main() {}
diff --git a/src/test/ui/pub/pub-ident-fn-3.stderr b/src/test/ui/pub/pub-ident-fn-3.stderr
new file mode 100644
index 00000000000..6d3d4e592c8
--- /dev/null
+++ b/src/test/ui/pub/pub-ident-fn-3.stderr
@@ -0,0 +1,8 @@
+error: missing `fn` or `struct` for function or struct definition
+  --> $DIR/pub-ident-fn-3.rs:4:8
+   |
+LL |     pub bar();
+   |     ---^--- help: if you meant to call a macro, try: `bar!`
+
+error: aborting due to previous error
+