diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 5b1cd0bcb3f..7195c41eae9 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2799,7 +2799,7 @@ declare_lint! { /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813 /// [future-incompatible]: ../index.md#future-incompatible-lints pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, - Allow, + Warn, "trailing semicolon in macro body used as expression", @future_incompatible = FutureIncompatibleInfo { reference: "issue #79813 ", diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 7afe52a3fd6..676695795ba 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -290,7 +290,7 @@ macro_rules! dbg { // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!` // will be malformed. () => { - $crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!()); + $crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!()) }; ($val:expr $(,)?) => { // Use of `match` here is intentional because it affects the lifetimes diff --git a/src/test/ui/hygiene/auxiliary/intercrate.rs b/src/test/ui/hygiene/auxiliary/intercrate.rs index 10d399ba54e..0685358851e 100644 --- a/src/test/ui/hygiene/auxiliary/intercrate.rs +++ b/src/test/ui/hygiene/auxiliary/intercrate.rs @@ -5,7 +5,7 @@ pub mod foo { mod bar { fn f() -> u32 { 1 } pub macro m() { - f(); + f() } } } diff --git a/src/test/ui/hygiene/hygienic-label-1.rs b/src/test/ui/hygiene/hygienic-label-1.rs index 66361eec21a..a06d9255ab5 100644 --- a/src/test/ui/hygiene/hygienic-label-1.rs +++ b/src/test/ui/hygiene/hygienic-label-1.rs @@ -3,5 +3,5 @@ macro_rules! foo { } pub fn main() { - 'x: loop { foo!() } + 'x: loop { foo!(); } } diff --git a/src/test/ui/hygiene/hygienic-label-1.stderr b/src/test/ui/hygiene/hygienic-label-1.stderr index 97a7240b906..c1ed861836c 100644 --- a/src/test/ui/hygiene/hygienic-label-1.stderr +++ b/src/test/ui/hygiene/hygienic-label-1.stderr @@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x` LL | () => { break 'x; } | ^^ undeclared label `'x` ... -LL | 'x: loop { foo!() } - | ------ in this macro invocation +LL | 'x: loop { foo!(); } + | ------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/hygienic-label-3.rs b/src/test/ui/hygiene/hygienic-label-3.rs index a81eb842259..ab0559e1b6a 100644 --- a/src/test/ui/hygiene/hygienic-label-3.rs +++ b/src/test/ui/hygiene/hygienic-label-3.rs @@ -4,6 +4,6 @@ macro_rules! foo { pub fn main() { 'x: for _ in 0..1 { - foo!() + foo!(); }; } diff --git a/src/test/ui/hygiene/hygienic-label-3.stderr b/src/test/ui/hygiene/hygienic-label-3.stderr index 52840049f82..29d1b67e09f 100644 --- a/src/test/ui/hygiene/hygienic-label-3.stderr +++ b/src/test/ui/hygiene/hygienic-label-3.stderr @@ -4,8 +4,8 @@ error[E0426]: use of undeclared label `'x` LL | () => { break 'x; } | ^^ undeclared label `'x` ... -LL | foo!() - | ------ in this macro invocation +LL | foo!(); + | ------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/lint/semicolon-in-expressions-from-macros/allow-semicolon-in-expressions-from-macros.rs b/src/test/ui/lint/semicolon-in-expressions-from-macros/allow-semicolon-in-expressions-from-macros.rs deleted file mode 100644 index 6f9e6ec0a57..00000000000 --- a/src/test/ui/lint/semicolon-in-expressions-from-macros/allow-semicolon-in-expressions-from-macros.rs +++ /dev/null @@ -1,15 +0,0 @@ -// check-pass -// Ensure that trailing semicolons are allowed by default - -macro_rules! foo { - () => { - true; - } -} - -fn main() { - let val = match true { - true => false, - _ => foo!() - }; -} diff --git a/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs new file mode 100644 index 00000000000..2c63311e659 --- /dev/null +++ b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs @@ -0,0 +1,16 @@ +// check-pass +// Ensure that trailing semicolons cause warnings by default + +macro_rules! foo { + () => { + true; //~ WARN trailing semicolon in macro + //~| WARN this was previously + } +} + +fn main() { + let _val = match true { + true => false, + _ => foo!() + }; +} diff --git a/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr new file mode 100644 index 00000000000..d770a8c8f36 --- /dev/null +++ b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr @@ -0,0 +1,16 @@ +warning: trailing semicolon in macro used in expression position + --> $DIR/warn-semicolon-in-expressions-from-macros.rs:6:13 + | +LL | true; + | ^ +... +LL | _ => foo!() + | ------ in this macro invocation + | + = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79813 + = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +warning: 1 warning emitted + diff --git a/src/test/ui/macros/macro-context.rs b/src/test/ui/macros/macro-context.rs index 13e179578ad..d09fdf118e6 100644 --- a/src/test/ui/macros/macro-context.rs +++ b/src/test/ui/macros/macro-context.rs @@ -6,6 +6,8 @@ macro_rules! m { //~| ERROR macro expansion ignores token `;` //~| ERROR cannot find type `i` in this scope //~| ERROR cannot find value `i` in this scope + //~| WARN trailing semicolon in macro + //~| WARN this was previously } fn main() { diff --git a/src/test/ui/macros/macro-context.stderr b/src/test/ui/macros/macro-context.stderr index 5ed73b7fb93..3b8a6f17491 100644 --- a/src/test/ui/macros/macro-context.stderr +++ b/src/test/ui/macros/macro-context.stderr @@ -64,7 +64,21 @@ LL | let i = m!(); | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 6 previous errors +warning: trailing semicolon in macro used in expression position + --> $DIR/macro-context.rs:3:15 + | +LL | () => ( i ; typeof ); + | ^ +... +LL | let i = m!(); + | ---- in this macro invocation + | + = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79813 + = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 6 previous errors; 1 warning emitted Some errors have detailed explanations: E0412, E0425. For more information about an error, try `rustc --explain E0412`. diff --git a/src/test/ui/macros/macro-in-expression-context.fixed b/src/test/ui/macros/macro-in-expression-context.fixed index df36db0f49e..3fb4e0dbfa6 100644 --- a/src/test/ui/macros/macro-in-expression-context.fixed +++ b/src/test/ui/macros/macro-in-expression-context.fixed @@ -3,6 +3,10 @@ macro_rules! foo { () => { assert_eq!("A", "A"); + //~^ WARN trailing semicolon in macro + //~| WARN this was previously + //~| NOTE for more information + //~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default assert_eq!("B", "B"); } //~^^ ERROR macro expansion ignores token `assert_eq` and any following @@ -12,4 +16,8 @@ macro_rules! foo { fn main() { foo!(); //~^ NOTE caused by the macro expansion here + //~| NOTE in this expansion + //~| NOTE in this expansion + //~| NOTE in this expansion + //~| NOTE in this expansion } diff --git a/src/test/ui/macros/macro-in-expression-context.rs b/src/test/ui/macros/macro-in-expression-context.rs index b3f5e568967..fc434071dcd 100644 --- a/src/test/ui/macros/macro-in-expression-context.rs +++ b/src/test/ui/macros/macro-in-expression-context.rs @@ -3,6 +3,10 @@ macro_rules! foo { () => { assert_eq!("A", "A"); + //~^ WARN trailing semicolon in macro + //~| WARN this was previously + //~| NOTE for more information + //~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default assert_eq!("B", "B"); } //~^^ ERROR macro expansion ignores token `assert_eq` and any following @@ -12,4 +16,8 @@ macro_rules! foo { fn main() { foo!() //~^ NOTE caused by the macro expansion here + //~| NOTE in this expansion + //~| NOTE in this expansion + //~| NOTE in this expansion + //~| NOTE in this expansion } diff --git a/src/test/ui/macros/macro-in-expression-context.stderr b/src/test/ui/macros/macro-in-expression-context.stderr index d27d6fbaef7..ddc1709a270 100644 --- a/src/test/ui/macros/macro-in-expression-context.stderr +++ b/src/test/ui/macros/macro-in-expression-context.stderr @@ -1,5 +1,5 @@ error: macro expansion ignores token `assert_eq` and any following - --> $DIR/macro-in-expression-context.rs:6:9 + --> $DIR/macro-in-expression-context.rs:10:9 | LL | assert_eq!("B", "B"); | ^^^^^^^^^ @@ -11,5 +11,19 @@ LL | foo!() | = note: the usage of `foo!` is likely invalid in expression context -error: aborting due to previous error +warning: trailing semicolon in macro used in expression position + --> $DIR/macro-in-expression-context.rs:5:29 + | +LL | assert_eq!("A", "A"); + | ^ +... +LL | foo!() + | ------ in this macro invocation + | + = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79813 + = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/proc-macro/nested-nonterminal-tokens.rs b/src/test/ui/proc-macro/nested-nonterminal-tokens.rs index 2f5af10a40a..04d34e21cdc 100644 --- a/src/test/ui/proc-macro/nested-nonterminal-tokens.rs +++ b/src/test/ui/proc-macro/nested-nonterminal-tokens.rs @@ -17,7 +17,7 @@ macro_rules! wrap { (first, $e:expr) => { wrap!(second, $e + 1) }; (second, $e:expr) => { wrap!(third, $e + 2) }; (third, $e:expr) => { - print_bang!($e + 3); + print_bang!($e + 3) }; }