From ed3b751799b0d9a754846bd754d9b43cf6c7394b Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 24 Sep 2021 13:31:01 +0100 Subject: Give better error for `macro_rules! name!` --- compiler/rustc_parse/src/parser/item.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 0e2222bf840..624390a406f 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1547,6 +1547,20 @@ impl<'a> Parser<'a> { self.expect(&token::Not)?; // `!` let ident = self.parse_ident()?; + + if self.eat(&token::Not) { + // Handle macro_rules! foo! + let span = self.prev_token.span; + self.struct_span_err(span, "macro names aren't followed by a `!`") + .span_suggestion( + span, + "remove the `!`", + "".to_owned(), + Applicability::MachineApplicable, + ) + .emit(); + } + let body = self.parse_mac_args()?; self.eat_semi_for_macro_if_needed(&body); self.complain_if_pub_macro(vis, true); -- cgit 1.4.1-3-g733a5