From 33ebc20513c692691216ee1924d5cd29aca6f6aa Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 28 Feb 2020 14:10:33 +0100 Subject: [PATCH] Turn trailing tokens in `assert!()` into hard errors --- src/librustc_builtin_macros/assert.rs | 12 ++++-------- src/test/ui/macros/assert-trailing-junk.rs | 6 +++--- src/test/ui/macros/assert-trailing-junk.stderr | 14 ++++---------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/librustc_builtin_macros/assert.rs b/src/librustc_builtin_macros/assert.rs index 5da4a540940c2..09ff770e87b59 100644 --- a/src/librustc_builtin_macros/assert.rs +++ b/src/librustc_builtin_macros/assert.rs @@ -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) diff --git a/src/test/ui/macros/assert-trailing-junk.rs b/src/test/ui/macros/assert-trailing-junk.rs index 676ae05bf0fa6..cd7faf9bf8bfb 100644 --- a/src/test/ui/macros/assert-trailing-junk.rs +++ b/src/test/ui/macros/assert-trailing-junk.rs @@ -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 } diff --git a/src/test/ui/macros/assert-trailing-junk.stderr b/src/test/ui/macros/assert-trailing-junk.stderr index 4d18a531a800c..84a6768b3f453 100644 --- a/src/test/ui/macros/assert-trailing-junk.stderr +++ b/src/test/ui/macros/assert-trailing-junk.stderr @@ -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