Skip to content

Commit 3f43f22

Browse files
authored
Rollup merge of rust-lang#89221 - aDotInTheVoid:macro-error-1, r=estebank
Give better error for `macro_rules! name!` r? `@estebank` `@rustbot` modify labels: +A-diagnostics +A-parser
2 parents 913b9df + ed3b751 commit 3f43f22

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

compiler/rustc_parse/src/parser/item.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,20 @@ impl<'a> Parser<'a> {
15471547
self.expect(&token::Not)?; // `!`
15481548

15491549
let ident = self.parse_ident()?;
1550+
1551+
if self.eat(&token::Not) {
1552+
// Handle macro_rules! foo!
1553+
let span = self.prev_token.span;
1554+
self.struct_span_err(span, "macro names aren't followed by a `!`")
1555+
.span_suggestion(
1556+
span,
1557+
"remove the `!`",
1558+
"".to_owned(),
1559+
Applicability::MachineApplicable,
1560+
)
1561+
.emit();
1562+
}
1563+
15501564
let body = self.parse_mac_args()?;
15511565
self.eat_semi_for_macro_if_needed(&body);
15521566
self.complain_if_pub_macro(vis, true);
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
#[allow(unused_macros)]
3+
4+
macro_rules! foo { //~ ERROR macro names aren't followed by a `!`
5+
() => {};
6+
}
7+
8+
fn main() {}

src/test/ui/macros/bang-after-name.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-rustfix
2+
#[allow(unused_macros)]
3+
4+
macro_rules! foo! { //~ ERROR macro names aren't followed by a `!`
5+
() => {};
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: macro names aren't followed by a `!`
2+
--> $DIR/bang-after-name.rs:4:17
3+
|
4+
LL | macro_rules! foo! {
5+
| ^ help: remove the `!`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)