Skip to content

Commit

Permalink
Rollup merge of rust-lang#56491 - euclio:assert-error, r=estebank
Browse files Browse the repository at this point in the history
emit error with span for empty asserts

Fixes rust-lang#55547.
  • Loading branch information
GuillaumeGomez authored Dec 10, 2018
2 parents 1137d29 + a367cec commit dec7b19
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libsyntax_ext/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ pub fn expand_assert<'cx>(
tts: &[TokenTree],
) -> Box<dyn MacResult + 'cx> {
let mut parser = cx.new_parser_from_tts(tts);

if parser.token == token::Eof {
cx.struct_span_err(sp, "macro requires a boolean expression as an argument")
.span_label(sp, "boolean expression required")
.emit();
return DummyResult::expr(sp);
}

let cond_expr = panictry!(parser.parse_expr());
let custom_msg_args = if parser.eat(&token::Comma) {
let ts = parser.parse_tokens();
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/macros/assert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
assert!(); //~ ERROR requires a boolean expression
debug_assert!(); //~ ERROR requires a boolean expression
}
16 changes: 16 additions & 0 deletions src/test/ui/macros/assert.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: macro requires a boolean expression as an argument
--> $DIR/assert.rs:2:5
|
LL | assert!(); //~ ERROR requires a boolean expression
| ^^^^^^^^^^ boolean expression required

error: macro requires a boolean expression as an argument
--> $DIR/assert.rs:3:5
|
LL | debug_assert!(); //~ ERROR requires a boolean expression
| ^^^^^^^^^^^^^^^^ boolean expression required
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 2 previous errors

0 comments on commit dec7b19

Please sign in to comment.