diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index e3bd2ca01310b..a2384b59048d5 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -24,6 +24,14 @@ pub fn expand_assert<'cx>( tts: &[TokenTree], ) -> Box { 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(); diff --git a/src/test/ui/macros/assert.rs b/src/test/ui/macros/assert.rs new file mode 100644 index 0000000000000..8732cb58d74a6 --- /dev/null +++ b/src/test/ui/macros/assert.rs @@ -0,0 +1,4 @@ +fn main() { + assert!(); //~ ERROR requires a boolean expression + debug_assert!(); //~ ERROR requires a boolean expression +} diff --git a/src/test/ui/macros/assert.stderr b/src/test/ui/macros/assert.stderr new file mode 100644 index 0000000000000..89faba0cf63dd --- /dev/null +++ b/src/test/ui/macros/assert.stderr @@ -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 +