diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a5adb37f7455c..cc854e938ffcb 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 0000000000000..fdbea7cf487eb --- /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 0000000000000..6d3d4e592c8ed --- /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 +