Give better error for macro_rules! name!
This commit is contained in:
parent
15d9ba0133
commit
ed3b751799
4 changed files with 38 additions and 0 deletions
|
@ -1547,6 +1547,20 @@ impl<'a> Parser<'a> {
|
||||||
self.expect(&token::Not)?; // `!`
|
self.expect(&token::Not)?; // `!`
|
||||||
|
|
||||||
let ident = self.parse_ident()?;
|
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()?;
|
let body = self.parse_mac_args()?;
|
||||||
self.eat_semi_for_macro_if_needed(&body);
|
self.eat_semi_for_macro_if_needed(&body);
|
||||||
self.complain_if_pub_macro(vis, true);
|
self.complain_if_pub_macro(vis, true);
|
||||||
|
|
8
src/test/ui/macros/bang-after-name.fixed
Normal file
8
src/test/ui/macros/bang-after-name.fixed
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
|
||||||
|
macro_rules! foo { //~ ERROR macro names aren't followed by a `!`
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
src/test/ui/macros/bang-after-name.rs
Normal file
8
src/test/ui/macros/bang-after-name.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// run-rustfix
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
|
||||||
|
macro_rules! foo! { //~ ERROR macro names aren't followed by a `!`
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
src/test/ui/macros/bang-after-name.stderr
Normal file
8
src/test/ui/macros/bang-after-name.stderr
Normal file
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue