Make assert! ensure the macro is parsed completely
This commit is contained in:
parent
258e3b3a75
commit
dfc0861085
@ -74,7 +74,7 @@ fn parse_assert<'a>(
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
Ok(Assert {
|
||||
let assert = Assert {
|
||||
cond_expr: parser.parse_expr()?,
|
||||
custom_message: if parser.eat(&token::Comma) {
|
||||
let ts = parser.parse_tokens();
|
||||
@ -86,5 +86,12 @@ fn parse_assert<'a>(
|
||||
} else {
|
||||
None
|
||||
},
|
||||
})
|
||||
};
|
||||
|
||||
if parser.token != token::Eof {
|
||||
parser.expect_one_of(&[], &[])?;
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
Ok(assert)
|
||||
}
|
||||
|
14
src/test/ui/macros/assert-trailing-junk.rs
Normal file
14
src/test/ui/macros/assert-trailing-junk.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Ensure assert macro does not ignore trailing garbage.
|
||||
//
|
||||
// See https://github.com/rust-lang/rust/issues/60024 for details.
|
||||
|
||||
fn main() {
|
||||
assert!(true some extra junk, "whatever");
|
||||
//~^ ERROR expected one of
|
||||
|
||||
assert!(true some extra junk);
|
||||
//~^ ERROR expected one of
|
||||
|
||||
assert!(true, "whatever" blah);
|
||||
//~^ ERROR no rules expected
|
||||
}
|
22
src/test/ui/macros/assert-trailing-junk.stderr
Normal file
22
src/test/ui/macros/assert-trailing-junk.stderr
Normal file
@ -0,0 +1,22 @@
|
||||
error: expected one of `,`, `.`, `?`, or an operator, found `some`
|
||||
--> $DIR/assert-trailing-junk.rs:6:18
|
||||
|
|
||||
LL | assert!(true some extra junk, "whatever");
|
||||
| ^^^^ expected one of `,`, `.`, `?`, or an operator here
|
||||
|
||||
error: expected one of `,`, `.`, `?`, or an operator, found `some`
|
||||
--> $DIR/assert-trailing-junk.rs:9:18
|
||||
|
|
||||
LL | assert!(true some extra junk);
|
||||
| ^^^^ expected one of `,`, `.`, `?`, or an operator here
|
||||
|
||||
error: no rules expected the token `blah`
|
||||
--> $DIR/assert-trailing-junk.rs:12:30
|
||||
|
|
||||
LL | assert!(true, "whatever" blah);
|
||||
| -^^^^ no rules expected this token in macro call
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user