From 30b779f3984fa41a54f30c78bd4559233b4e3c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 19 Apr 2019 11:04:41 -0700 Subject: [PATCH] Remove assumption from recovery code --- src/libsyntax/parse/parser.rs | 2 +- src/test/ui/pub/pub-ident-fn-3.rs | 8 ++++++++ src/test/ui/pub/pub-ident-fn-3.stderr | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/pub/pub-ident-fn-3.rs create mode 100644 src/test/ui/pub/pub-ident-fn-3.stderr 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 +