Skip to content

Commit 33ebc20

Browse files
Turn trailing tokens in assert!() into hard errors
1 parent 865b44a commit 33ebc20

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/librustc_builtin_macros/assert.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ fn parse_assert<'a>(
8080
// my_function();
8181
// );
8282
//
83-
// Warn about semicolon and suggest removing it. Eventually, this should be turned into an
84-
// error.
83+
// Emit an error about semicolon and suggest removing it.
8584
if parser.token == token::Semi {
86-
let mut err = cx.struct_span_warn(sp, "macro requires an expression as an argument");
85+
let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument");
8786
err.span_suggestion(
8887
parser.token.span,
8988
"try removing semicolon",
9089
String::new(),
9190
Applicability::MaybeIncorrect,
9291
);
93-
err.note("this is going to be an error in the future");
9492
err.emit();
9593

9694
parser.bump();
@@ -101,19 +99,17 @@ fn parse_assert<'a>(
10199
//
102100
// assert!(true "error message");
103101
//
104-
// Parse this as an actual message, and suggest inserting a comma. Eventually, this should be
105-
// turned into an error.
102+
// Emit an error and suggest inserting a comma.
106103
let custom_message =
107104
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
108-
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
105+
let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal");
109106
let comma_span = parser.prev_token.span.shrink_to_hi();
110107
err.span_suggestion_short(
111108
comma_span,
112109
"try adding a comma",
113110
", ".to_string(),
114111
Applicability::MaybeIncorrect,
115112
);
116-
err.note("this is going to be an error in the future");
117113
err.emit();
118114

119115
parse_custom_message(&mut parser)

src/test/ui/macros/assert-trailing-junk.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ fn main() {
1313
//~^ ERROR no rules expected
1414

1515
assert!(true "whatever" blah);
16-
//~^ WARN unexpected string literal
16+
//~^ ERROR unexpected string literal
1717
//~^^ ERROR no rules expected
1818

1919
assert!(true;);
20-
//~^ WARN macro requires an expression
20+
//~^ ERROR macro requires an expression
2121

2222
assert!(false || true "error message");
23-
//~^ WARN unexpected string literal
23+
//~^ ERROR unexpected string literal
2424
}

src/test/ui/macros/assert-trailing-junk.stderr

+4-10
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ LL | assert!(true, "whatever" blah);
1818
| |
1919
| help: missing comma here
2020

21-
warning: unexpected string literal
21+
error: unexpected string literal
2222
--> $DIR/assert-trailing-junk.rs:15:18
2323
|
2424
LL | assert!(true "whatever" blah);
2525
| -^^^^^^^^^^
2626
| |
2727
| help: try adding a comma
28-
|
29-
= note: this is going to be an error in the future
3028

3129
error: no rules expected the token `blah`
3230
--> $DIR/assert-trailing-junk.rs:15:29
@@ -36,25 +34,21 @@ LL | assert!(true "whatever" blah);
3634
| |
3735
| help: missing comma here
3836

39-
warning: macro requires an expression as an argument
37+
error: macro requires an expression as an argument
4038
--> $DIR/assert-trailing-junk.rs:19:5
4139
|
4240
LL | assert!(true;);
4341
| ^^^^^^^^^^^^-^^
4442
| |
4543
| help: try removing semicolon
46-
|
47-
= note: this is going to be an error in the future
4844

49-
warning: unexpected string literal
45+
error: unexpected string literal
5046
--> $DIR/assert-trailing-junk.rs:22:27
5147
|
5248
LL | assert!(false || true "error message");
5349
| -^^^^^^^^^^^^^^^
5450
| |
5551
| help: try adding a comma
56-
|
57-
= note: this is going to be an error in the future
5852

59-
error: aborting due to 4 previous errors
53+
error: aborting due to 7 previous errors
6054

0 commit comments

Comments
 (0)