Skip to content

Commit

Permalink
Rollup merge of rust-lang#89221 - aDotInTheVoid:macro-error-1, r=este…
Browse files Browse the repository at this point in the history
…bank

Give better error for `macro_rules! name!`

r? `@estebank`

`@rustbot` modify labels: +A-diagnostics +A-parser
  • Loading branch information
Manishearth committed Sep 24, 2021
2 parents 913b9df + ed3b751 commit 3f43f22
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/macros/bang-after-name.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix
#[allow(unused_macros)]

macro_rules! foo { //~ ERROR macro names aren't followed by a `!`
() => {};
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/macros/bang-after-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix
#[allow(unused_macros)]

macro_rules! foo! { //~ ERROR macro names aren't followed by a `!`
() => {};
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/macros/bang-after-name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: macro names aren't followed by a `!`
--> $DIR/bang-after-name.rs:4:17
|
LL | macro_rules! foo! {
| ^ help: remove the `!`

error: aborting due to previous error

0 comments on commit 3f43f22

Please sign in to comment.