Turn trailing tokens in assert!()
into hard errors
This commit is contained in:
parent
865b44a3e3
commit
33ebc20513
@ -80,17 +80,15 @@ fn parse_assert<'a>(
|
||||
// my_function();
|
||||
// );
|
||||
//
|
||||
// Warn about semicolon and suggest removing it. Eventually, this should be turned into an
|
||||
// error.
|
||||
// Emit an error about semicolon and suggest removing it.
|
||||
if parser.token == token::Semi {
|
||||
let mut err = cx.struct_span_warn(sp, "macro requires an expression as an argument");
|
||||
let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument");
|
||||
err.span_suggestion(
|
||||
parser.token.span,
|
||||
"try removing semicolon",
|
||||
String::new(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.note("this is going to be an error in the future");
|
||||
err.emit();
|
||||
|
||||
parser.bump();
|
||||
@ -101,11 +99,10 @@ fn parse_assert<'a>(
|
||||
//
|
||||
// assert!(true "error message");
|
||||
//
|
||||
// Parse this as an actual message, and suggest inserting a comma. Eventually, this should be
|
||||
// turned into an error.
|
||||
// Emit an error and suggest inserting a comma.
|
||||
let custom_message =
|
||||
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
|
||||
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
|
||||
let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal");
|
||||
let comma_span = parser.prev_token.span.shrink_to_hi();
|
||||
err.span_suggestion_short(
|
||||
comma_span,
|
||||
@ -113,7 +110,6 @@ fn parse_assert<'a>(
|
||||
", ".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.note("this is going to be an error in the future");
|
||||
err.emit();
|
||||
|
||||
parse_custom_message(&mut parser)
|
||||
|
@ -13,12 +13,12 @@ fn main() {
|
||||
//~^ ERROR no rules expected
|
||||
|
||||
assert!(true "whatever" blah);
|
||||
//~^ WARN unexpected string literal
|
||||
//~^ ERROR unexpected string literal
|
||||
//~^^ ERROR no rules expected
|
||||
|
||||
assert!(true;);
|
||||
//~^ WARN macro requires an expression
|
||||
//~^ ERROR macro requires an expression
|
||||
|
||||
assert!(false || true "error message");
|
||||
//~^ WARN unexpected string literal
|
||||
//~^ ERROR unexpected string literal
|
||||
}
|
||||
|
@ -18,15 +18,13 @@ LL | assert!(true, "whatever" blah);
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
warning: unexpected string literal
|
||||
error: unexpected string literal
|
||||
--> $DIR/assert-trailing-junk.rs:15:18
|
||||
|
|
||||
LL | assert!(true "whatever" blah);
|
||||
| -^^^^^^^^^^
|
||||
| |
|
||||
| help: try adding a comma
|
||||
|
|
||||
= note: this is going to be an error in the future
|
||||
|
||||
error: no rules expected the token `blah`
|
||||
--> $DIR/assert-trailing-junk.rs:15:29
|
||||
@ -36,25 +34,21 @@ LL | assert!(true "whatever" blah);
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
warning: macro requires an expression as an argument
|
||||
error: macro requires an expression as an argument
|
||||
--> $DIR/assert-trailing-junk.rs:19:5
|
||||
|
|
||||
LL | assert!(true;);
|
||||
| ^^^^^^^^^^^^-^^
|
||||
| |
|
||||
| help: try removing semicolon
|
||||
|
|
||||
= note: this is going to be an error in the future
|
||||
|
||||
warning: unexpected string literal
|
||||
error: unexpected string literal
|
||||
--> $DIR/assert-trailing-junk.rs:22:27
|
||||
|
|
||||
LL | assert!(false || true "error message");
|
||||
| -^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: try adding a comma
|
||||
|
|
||||
= note: this is going to be an error in the future
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user