From ce79e843eff4a87203d651bf309fbe716a3719fe Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 12 Jul 2026 21:53:46 -0700 Subject: [PATCH 1/4] Move a subset of `semicolon-in-expressions-from-macros` from `tests/ui/lint` to `tests/ui/macros` Subsequent commits will change this lint into an error, so the tests no longer belong under `lint`. Make the rename a separate commit to make the subsequent changes easier to diff. The test for the lint itself (which validates behavior when allowing the lint) is removed entirely. --- .../semicolon-in-expressions-from-macros.rs | 52 ----- ...emicolon-in-expressions-from-macros.stderr | 178 ------------------ .../auxiliary/foreign-crate.rs | 0 .../foreign-crate.rs | 0 ...rn-semicolon-in-expressions-from-macros.rs | 0 ...emicolon-in-expressions-from-macros.stderr | 0 6 files changed, 230 deletions(-) delete mode 100644 tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.rs delete mode 100644 tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr rename tests/ui/{lint => macros}/semicolon-in-expressions-from-macros/auxiliary/foreign-crate.rs (100%) rename tests/ui/{lint => macros}/semicolon-in-expressions-from-macros/foreign-crate.rs (100%) rename tests/ui/{lint => macros}/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs (100%) rename tests/ui/{lint => macros}/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr (100%) diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.rs b/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.rs deleted file mode 100644 index 28c2a2c33abeb..0000000000000 --- a/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.rs +++ /dev/null @@ -1,52 +0,0 @@ -//@ check-pass -//@ edition:2018 -#![feature(stmt_expr_attributes)] -#![warn(semicolon_in_expressions_from_macros)] - -#[allow(dead_code)] -macro_rules! foo { - ($val:ident) => { - true; //~ WARN trailing semicolon in macro - //~| WARN this was previously accepted - //~| WARN trailing semicolon in macro - //~| WARN this was previously accepted - //~| WARN trailing semicolon in macro - //~| WARN this was previously accepted - } -} - -#[allow(semicolon_in_expressions_from_macros)] -async fn bar() { - foo!(first); -} - -fn main() { - #[allow(semicolon_in_expressions_from_macros)] - let _ = { - foo!(first) - }; - - #[allow(semicolon_in_expressions_from_macros)] - let _ = foo!(second); - - #[allow(semicolon_in_expressions_from_macros)] - fn inner() { - let _ = foo!(third); - } - - #[allow(semicolon_in_expressions_from_macros)] - async { - let _ = foo!(fourth); - }; - - let _ = { - foo!(warn_in_block) - }; - - let _ = foo!(warn_in_expr); - - // This `#[allow]` does not work, since the attribute gets dropped - // when we expand the macro - let _ = #[allow(semicolon_in_expressions_from_macros)] foo!(allow_does_not_work); - //~^ WARN unused attribute -} diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr b/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr deleted file mode 100644 index 5a426be83f861..0000000000000 --- a/tests/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr +++ /dev/null @@ -1,178 +0,0 @@ -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | foo!(warn_in_block) - | ------------------- in this macro invocation - | - = note: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo` - = 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: the lint level is defined here - --> $DIR/semicolon-in-expressions-from-macros.rs:4:9 - | -LL | #![warn(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(warn_in_expr); - | ------------------ in this macro invocation - | - = 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: unused attribute `allow` - --> $DIR/semicolon-in-expressions-from-macros.rs:50:13 - | -LL | let _ = #[allow(semicolon_in_expressions_from_macros)] foo!(allow_does_not_work); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo` - --> $DIR/semicolon-in-expressions-from-macros.rs:50:60 - | -LL | let _ = #[allow(semicolon_in_expressions_from_macros)] foo!(allow_does_not_work); - | ^^^ - = note: requested on the command line with `-W unused-attributes` - -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = #[allow(semicolon_in_expressions_from_macros)] foo!(allow_does_not_work); - | ------------------------- in this macro invocation - | - = 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: 4 warnings emitted - -Future incompatibility report: Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | foo!(first) - | ----------- in this macro invocation - | - = note: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo` - = 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) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(second); - | ------------ in this macro invocation - | - = 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) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(third); - | ----------- in this macro invocation - | - = 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) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(fourth); - | ------------ in this macro invocation - | - = 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) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | foo!(warn_in_block) - | ------------------- in this macro invocation - | - = note: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo` - = 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: the lint level is defined here - --> $DIR/semicolon-in-expressions-from-macros.rs:4:9 - | -LL | #![warn(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(warn_in_expr); - | ------------------ in this macro invocation - | - = 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: the lint level is defined here - --> $DIR/semicolon-in-expressions-from-macros.rs:4:9 - | -LL | #![warn(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/semicolon-in-expressions-from-macros.rs:9:13 - | -LL | true; - | ^ -... -LL | let _ = #[allow(semicolon_in_expressions_from_macros)] foo!(allow_does_not_work); - | ------------------------- in this macro invocation - | - = 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: the lint level is defined here - --> $DIR/semicolon-in-expressions-from-macros.rs:4:9 - | -LL | #![warn(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/auxiliary/foreign-crate.rs b/tests/ui/macros/semicolon-in-expressions-from-macros/auxiliary/foreign-crate.rs similarity index 100% rename from tests/ui/lint/semicolon-in-expressions-from-macros/auxiliary/foreign-crate.rs rename to tests/ui/macros/semicolon-in-expressions-from-macros/auxiliary/foreign-crate.rs diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs b/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs similarity index 100% rename from tests/ui/lint/semicolon-in-expressions-from-macros/foreign-crate.rs rename to tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs similarity index 100% rename from tests/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs rename to tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs diff --git a/tests/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr similarity index 100% rename from tests/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr rename to tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr From 6d365c2e39cd5f4e0e944ec0cba01026c9851e24 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 12 Jul 2026 22:59:35 -0700 Subject: [PATCH 2/4] tests/ui/macros/issue-84195-lint-anon-const: Use a different buffered lint for testing issue-84195-lint-anon-const tests that we properly handle buffered lints. However, `semicolon_in_expressions_from_macros` is going away in favor of a hard error. So, switch to a different buffered lint, `unused_attributes`. --- .../ui/macros/issue-84195-lint-anon-const.rs | 10 ++++-- .../macros/issue-84195-lint-anon-const.stderr | 34 +++++-------------- tests/ui/macros/semicolon-in-exprs.rs | 15 -------- 3 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 tests/ui/macros/semicolon-in-exprs.rs diff --git a/tests/ui/macros/issue-84195-lint-anon-const.rs b/tests/ui/macros/issue-84195-lint-anon-const.rs index 71c7683201528..9486ec4f9e834 100644 --- a/tests/ui/macros/issue-84195-lint-anon-const.rs +++ b/tests/ui/macros/issue-84195-lint-anon-const.rs @@ -2,11 +2,15 @@ // Checks that we properly fire lints that occur inside // anon consts. -#![deny(semicolon_in_expressions_from_macros)] +#![deny(unused_attributes)] + +macro_rules! len2 { + () => { }; +} macro_rules! len { - () => { 0; }; //~ ERROR trailing semicolon - //~| WARN this was previously accepted + () => { { #[inline] len2!(); 0 } }; //~ ERROR `#[inline]` attribute cannot be used on macro calls + //~| WARN this was previously accepted } fn main() { diff --git a/tests/ui/macros/issue-84195-lint-anon-const.stderr b/tests/ui/macros/issue-84195-lint-anon-const.stderr index d9042adfc375a..08d635530d70f 100644 --- a/tests/ui/macros/issue-84195-lint-anon-const.stderr +++ b/tests/ui/macros/issue-84195-lint-anon-const.stderr @@ -1,39 +1,21 @@ -error: trailing semicolon in macro used in expression position - --> $DIR/issue-84195-lint-anon-const.rs:8:14 +error: `#[inline]` attribute cannot be used on macro calls + --> $DIR/issue-84195-lint-anon-const.rs:12:15 | -LL | () => { 0; }; - | ^ +LL | () => { { #[inline] len2!(); 0 } }; + | ^^^^^^^^^ ... LL | let val: [u8; len!()] = []; | ------ in this macro invocation | + = help: `#[inline]` can only be applied to functions = 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: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute note: the lint level is defined here --> $DIR/issue-84195-lint-anon-const.rs:5:9 | -LL | #![deny(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `len` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error -Future incompatibility report: Future breakage diagnostic: -error: trailing semicolon in macro used in expression position - --> $DIR/issue-84195-lint-anon-const.rs:8:14 - | -LL | () => { 0; }; - | ^ -... -LL | let val: [u8; len!()] = []; - | ------ in this macro invocation - | - = 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: the lint level is defined here - --> $DIR/issue-84195-lint-anon-const.rs:5:9 - | -LL | #![deny(semicolon_in_expressions_from_macros)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `len` (in Nightly builds, run with -Z macro-backtrace for more info) - diff --git a/tests/ui/macros/semicolon-in-exprs.rs b/tests/ui/macros/semicolon-in-exprs.rs deleted file mode 100644 index 1d6c9d895f067..0000000000000 --- a/tests/ui/macros/semicolon-in-exprs.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Regression test for https://github.com/rust-lang/rust/issues/156084. -//! This test can probably be removed again once -//! `semicolon_in_expressions_from_macros` is a hard error. -//@ check-pass -//@ aux-build:semicolon-in-exprs.rs -//@ edition: 2021 - -extern crate semicolon_in_exprs; - -macro_rules! inner { - [$($x:expr),*] => { [$($x),*] }; -} -fn main() { - let _v: Vec = semicolon_in_exprs::outer!(inner).into_iter().collect(); -} From 866dc51aeb4b9f0fd36ef13a08c3954e98515ece Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 12 Jul 2026 23:10:51 -0700 Subject: [PATCH 3/4] tests/ui/lint/expect-future_breakage-crash-issue-126521: Remove (depends on `semicolon_in_expressions_from_macros`) This regression test depends on specific quirky behavior of `semicolon_in_expressions_from_macros` (in which it got emitted despite an `allow`). Since that lint will become a hard error, the test would require substantial porting, and it's not obvious if it still applies. (Obvious alternative lints do not have this same issue of showing despite an `allow`.) --- ...pect-future_breakage-crash-issue-126521.rs | 38 -------------- ...-future_breakage-crash-issue-126521.stderr | 52 ------------------- 2 files changed, 90 deletions(-) delete mode 100644 tests/ui/lint/expect-future_breakage-crash-issue-126521.rs delete mode 100644 tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr diff --git a/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs b/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs deleted file mode 100644 index 19eb18fd17ba0..0000000000000 --- a/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs +++ /dev/null @@ -1,38 +0,0 @@ -//@ check-pass - -// This test covers similar crashes from both #126521 and #126751. - -macro_rules! foo { - ($val:ident) => { - true; - }; -} - -macro_rules! bar { - ($val:ident) => { - (5_i32.overflowing_sub(3)); - }; -} - -fn allow() { - #[allow(semicolon_in_expressions_from_macros)] - let _ = foo!(x); - - #[allow(semicolon_in_expressions_from_macros)] - let _ = bar!(x); -} - -// The `semicolon_in_expressions_from_macros` lint seems to be emitted even if the -// lint level is `allow` as shown in the function above. The behavior of `expect` -// should mirror this behavior. However, no `unfulfilled_lint_expectation` lint -// is emitted, since the expectation is theoretically fulfilled. -fn expect() { - #[expect(semicolon_in_expressions_from_macros)] - let _ = foo!(x); - - #[expect(semicolon_in_expressions_from_macros)] - let _ = bar!(x); -} - -fn main() { -} diff --git a/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr b/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr deleted file mode 100644 index 72a74c1579dd4..0000000000000 --- a/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr +++ /dev/null @@ -1,52 +0,0 @@ -Future incompatibility report: Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/expect-future_breakage-crash-issue-126521.rs:7:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(x); - | ------- in this macro invocation - | - = 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) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/expect-future_breakage-crash-issue-126521.rs:13:35 - | -LL | (5_i32.overflowing_sub(3)); - | ^ -... -LL | let _ = bar!(x); - | ------- in this macro invocation - | - = 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 `bar` (in Nightly builds, run with -Z macro-backtrace for more info) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/expect-future_breakage-crash-issue-126521.rs:7:13 - | -LL | true; - | ^ -... -LL | let _ = foo!(x); - | ------- in this macro invocation - | - = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -Future breakage diagnostic: -warning: trailing semicolon in macro used in expression position - --> $DIR/expect-future_breakage-crash-issue-126521.rs:13:35 - | -LL | (5_i32.overflowing_sub(3)); - | ^ -... -LL | let _ = bar!(x); - | ------- in this macro invocation - | - = note: this warning originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info) - From bc2be828a2a0123d220cd80d185c55e579109751 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 12 Jul 2026 23:15:51 -0700 Subject: [PATCH 4/4] Make `semicolon_in_expressions_from_macros` a hard error See https://github.com/rust-lang/rust/issues/79813, which has tracked the evolution of this issue: - We added it as an allow-by-default lint in December 2020. - We made it warn-by-default in July 2021. - We made it a future-incompat warn-in-deps in October 2022. - We made it deny-by-default in July 2025. Now, finally, let it become a hard error. Remove fields and parameters only tracked in order to detect the expression context and report the lint. Macro expansion now simply includes the semicolon to expand, without attempting to skip over it, and lets that produce an error. This will allow subsequent simplifications of macro handling. --- compiler/rustc_expand/src/base.rs | 8 +--- compiler/rustc_expand/src/diagnostics.rs | 11 ----- compiler/rustc_expand/src/expand.rs | 24 +--------- compiler/rustc_expand/src/mbe/macro_rules.rs | 35 ++------------ compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint_defs/src/builtin.rs | 47 ------------------- tests/ui/macros/lint-trailing-macro-call.rs | 3 +- .../ui/macros/lint-trailing-macro-call.stderr | 32 +++---------- tests/ui/macros/macro-context.rs | 6 +-- tests/ui/macros/macro-context.stderr | 37 ++------------- .../macros/macro-in-expression-context.fixed | 16 +------ .../ui/macros/macro-in-expression-context.rs | 16 +------ .../macros/macro-in-expression-context.stderr | 43 ++--------------- .../foreign-crate.rs | 4 +- .../foreign-crate.stderr | 15 ++++++ ...rn-semicolon-in-expressions-from-macros.rs | 5 +- ...emicolon-in-expressions-from-macros.stderr | 28 +++-------- tests/ui/macros/trace_faulty_macros.rs | 2 +- tests/ui/macros/trace_faulty_macros.stderr | 13 ++++- tests/ui/proc-macro/expand-expr.rs | 2 +- tests/ui/proc-macro/expand-expr.stderr | 6 +-- 21 files changed, 72 insertions(+), 282 deletions(-) create mode 100644 tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.stderr diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 24501524edf04..9ed98b500e3b5 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -274,11 +274,7 @@ impl<'cx> MacroExpanderResult<'cx> { arm_span: Span, macro_ident: Ident, ) -> Self { - // Emit the SEMICOLON_IN_EXPRESSIONS_FROM_MACROS deprecation lint. - let is_local = true; - - let parser = - ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, is_local, macro_ident, &[], &[]); + let parser = ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, macro_ident, &[], &[]); ExpandResult::Ready(Box::new(parser)) } } @@ -1183,7 +1179,6 @@ pub struct ExpansionData { pub dir_ownership: DirOwnership, /// Some parent node that is close to this macro call pub lint_node_id: NodeId, - pub is_trailing_mac: bool, } /// One of these is made during expansion and incrementally updated as we go; @@ -1235,7 +1230,6 @@ impl<'a> ExtCtxt<'a> { module: Default::default(), dir_ownership: DirOwnership::Owned { relative: None }, lint_node_id: ast::CRATE_NODE_ID, - is_trailing_mac: false, }, force_mode: false, expansions: FxIndexMap::default(), diff --git a/compiler/rustc_expand/src/diagnostics.rs b/compiler/rustc_expand/src/diagnostics.rs index a9493b8654805..347196203ed24 100644 --- a/compiler/rustc_expand/src/diagnostics.rs +++ b/compiler/rustc_expand/src/diagnostics.rs @@ -635,17 +635,6 @@ pub(crate) struct OrPatternsBackCompat { pub suggestion: String, } -#[derive(Diagnostic)] -#[diag("trailing semicolon in macro used in expression position")] -pub(crate) struct TrailingMacro { - #[note("macro invocations at the end of a block are treated as expressions")] - #[note( - "to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`" - )] - pub is_trailing: bool, - pub name: Ident, -} - #[derive(Diagnostic)] #[diag("unused attribute `{$attr_name}`")] pub(crate) struct UnusedBuiltinAttribute { diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 6dbac58cc6dbe..b8499a7e02eea 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -2511,31 +2511,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } fn flat_map_stmt(&mut self, node: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { - // FIXME: invocations in semicolon-less expressions positions are expanded as expressions, - // changing that requires some compatibility measures. if node.is_expr() { - // The only way that we can end up with a `MacCall` expression statement, - // (as opposed to a `StmtKind::MacCall`) is if we have a macro as the - // trailing expression in a block (e.g. `fn foo() { my_macro!() }`). - // Record this information, so that we can report a more specific - // `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint if needed. - // See #78991 for an investigation of treating macros in this position - // as statements, rather than expressions, during parsing. - return match &node.kind { - StmtKind::Expr(expr) - if matches!(**expr, ast::Expr { kind: ExprKind::MacCall(..), .. }) => - { - self.cx.current_expansion.is_trailing_mac = true; - // Don't use `assign_id` for this statement - it may get removed - // entirely due to a `#[cfg]` on the contained expression - let res = walk_flat_map_stmt(self, node); - self.cx.current_expansion.is_trailing_mac = false; - res - } - _ => walk_flat_map_stmt(self, node), - }; + return walk_flat_map_stmt(self, node); } - self.flat_map_node(node) } diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 4a0cacc977529..2310a7fe17999 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -17,9 +17,7 @@ use rustc_hir as hir; use rustc_hir::attrs::diagnostic::Directive; use rustc_hir::def::MacroKinds; use rustc_hir::find_attr; -use rustc_lint_defs::builtin::{ - RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, -}; +use rustc_lint_defs::builtin::RUST_2021_INCOMPATIBLE_OR_PATTERNS; use rustc_parse::exp; use rustc_parse::parser::{Parser, Recovery}; use rustc_session::Session; @@ -52,11 +50,7 @@ pub(crate) struct ParserAnyMacro<'a, 'b> { site_span: Span, /// The ident of the macro we're parsing macro_ident: Ident, - lint_node_id: NodeId, - is_trailing_mac: bool, arm_span: Span, - /// Whether or not this macro is defined in the current crate - is_local: bool, bindings: &'b [MacroRule], matched_rule_bindings: &'b [MatcherLoc], } @@ -70,10 +64,7 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { site_span, macro_ident, ref mut parser, - lint_node_id, arm_span, - is_trailing_mac, - is_local, bindings, matched_rule_bindings, } = *self; @@ -95,21 +86,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { } }; - // We allow semicolons at the end of expressions -- e.g., the semicolon in - // `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`, - // but `m!()` is allowed in expression positions (cf. issue #34706). - if kind == AstFragmentKind::Expr && parser.token == token::Semi { - if is_local { - parser.psess.buffer_lint( - SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, - parser.token.span, - lint_node_id, - diagnostics::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident }, - ); - } - parser.bump(); - } - // Make sure we don't have any tokens left to parse so we don't silently drop anything. let path = ast::Path::from_ident(macro_ident.with_span_pos(site_span)); ensure_complete_parse(parser, &path, kind.name(), site_span); @@ -122,7 +98,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { tts: TokenStream, site_span: Span, arm_span: Span, - is_local: bool, macro_ident: Ident, // bindings and lhs is for diagnostics bindings: &'b [MacroRule], @@ -136,10 +111,7 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> { // macro leaves unparsed tokens. site_span, macro_ident, - lint_node_id: cx.current_expansion.lint_node_id, - is_trailing_mac: cx.current_expansion.is_trailing_mac, arm_span, - is_local, bindings, matched_rule_bindings, } @@ -472,13 +444,12 @@ fn expand_macro<'cx, 'a: 'cx>( trace_macros_note(&mut cx.expansions, sp, msg); } - let is_local = is_defined_in_current_crate(node_id); - if is_local { + if is_defined_in_current_crate(node_id) { cx.resolver.record_macro_rule_usage(node_id, rule_index); } // Let the context choose how to interpret the result. Weird, but useful for X-macros. - Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, is_local, name, rules, lhs)) + Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, name, rules, lhs)) } Err(CanRetry::No(guar)) => { debug!("Will not retry matching as an error was emitted already"); diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index eaf9360cc3358..03def4ad8fa12 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -697,6 +697,7 @@ fn register_builtins(store: &mut LintStore) { "converted into hard error, \ see for more information", ); + store.register_removed("semicolon_in_expressions_from_macros", "converted into hard error"); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 693737bd89bdd..a71ab6bb6a8e4 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -102,7 +102,6 @@ pub mod hardwired { RUST_2024_INCOMPATIBLE_PAT, RUST_2024_PRELUDE_COLLISIONS, SELF_CONSTRUCTOR_FROM_OUTER_ITEM, - SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, SHADOWING_SUPERTRAIT_ITEMS, SINGLE_USE_LIFETIMES, STABLE_FEATURES, @@ -2843,52 +2842,6 @@ declare_lint! { }; } -declare_lint! { - /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons - /// in macro bodies when the macro is invoked in expression position. - /// This was previous accepted, but is being phased out. - /// - /// ### Example - /// - /// ```rust,compile_fail - /// #![deny(semicolon_in_expressions_from_macros)] - /// macro_rules! foo { - /// () => { true; } - /// } - /// - /// fn main() { - /// let val = match true { - /// true => false, - /// _ => foo!() - /// }; - /// } - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// Previous, Rust ignored trailing semicolon in a macro - /// body when a macro was invoked in expression position. - /// However, this makes the treatment of semicolons in the language - /// inconsistent, and could lead to unexpected runtime behavior - /// in some circumstances (e.g. if the macro author expects - /// a value to be dropped). - /// - /// This is a [future-incompatible] lint to transition this - /// to a hard error in the future. See [issue #79813] for more details. - /// - /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813 - /// [future-incompatible]: ../index.md#future-incompatible-lints - pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, - Deny, - "trailing semicolon in macro body used as expression", - @future_incompatible = FutureIncompatibleInfo { - reason: fcw!(FutureReleaseError #79813), - report_in_deps: true, - }; -} - declare_lint! { /// The `legacy_derive_helpers` lint detects derive helper attributes /// that are used before they are introduced. diff --git a/tests/ui/macros/lint-trailing-macro-call.rs b/tests/ui/macros/lint-trailing-macro-call.rs index 25fa91062c434..d0b75b912886c 100644 --- a/tests/ui/macros/lint-trailing-macro-call.rs +++ b/tests/ui/macros/lint-trailing-macro-call.rs @@ -4,8 +4,7 @@ macro_rules! expand_it { () => { - #[cfg(false)] 25; //~ ERROR trailing semicolon in macro - //~| WARN this was previously + #[cfg(false)] 25; //~ ERROR macro expansion ignores `;` } } diff --git a/tests/ui/macros/lint-trailing-macro-call.stderr b/tests/ui/macros/lint-trailing-macro-call.stderr index 1ff8c0c6f66f2..c5680c9c888c8 100644 --- a/tests/ui/macros/lint-trailing-macro-call.stderr +++ b/tests/ui/macros/lint-trailing-macro-call.stderr @@ -1,35 +1,17 @@ -error: trailing semicolon in macro used in expression position +error: macro expansion ignores `;` and any tokens following --> $DIR/lint-trailing-macro-call.rs:7:25 | LL | #[cfg(false)] 25; | ^ ... LL | expand_it!() - | ------------ in this macro invocation + | ------------ caused by the macro expansion here | - = note: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `expand_it` - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `expand_it` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: the usage of `expand_it!` is likely invalid in expression context +help: you might be missing a semicolon here + | +LL | expand_it!(); + | + error: aborting due to 1 previous error -Future incompatibility report: Future breakage diagnostic: -error: trailing semicolon in macro used in expression position - --> $DIR/lint-trailing-macro-call.rs:7:25 - | -LL | #[cfg(false)] 25; - | ^ -... -LL | expand_it!() - | ------------ in this macro invocation - | - = note: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `expand_it` - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `expand_it` (in Nightly builds, run with -Z macro-backtrace for more info) - diff --git a/tests/ui/macros/macro-context.rs b/tests/ui/macros/macro-context.rs index e1c24ba8b5705..44030d318cf6c 100644 --- a/tests/ui/macros/macro-context.rs +++ b/tests/ui/macros/macro-context.rs @@ -1,13 +1,11 @@ // (typeof used because it's surprisingly hard to find an unparsed token after a stmt) macro_rules! m { - () => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof` - //~| ERROR macro expansion ignores reserved keyword `typeof` + () => ( i ; typeof ); //~ ERROR macro expansion ignores `;` //~| ERROR macro expansion ignores `;` //~| ERROR macro expansion ignores `;` + //~| ERROR expected expression, found reserved keyword `typeof` //~| ERROR cannot find type `i` in this scope //~| ERROR cannot find value `i` in this scope - //~| ERROR trailing semicolon in macro - //~| WARN this was previously } fn main() { diff --git a/tests/ui/macros/macro-context.stderr b/tests/ui/macros/macro-context.stderr index 3ec1af3a82f82..11106aca06058 100644 --- a/tests/ui/macros/macro-context.stderr +++ b/tests/ui/macros/macro-context.stderr @@ -9,11 +9,11 @@ LL | let a: m!(); | = note: the usage of `m!` is likely invalid in type context -error: macro expansion ignores reserved keyword `typeof` and any tokens following - --> $DIR/macro-context.rs:3:17 +error: macro expansion ignores `;` and any tokens following + --> $DIR/macro-context.rs:3:15 | LL | () => ( i ; typeof ); - | ^^^^^^ + | ^ ... LL | let i = m!(); | ---- caused by the macro expansion here @@ -68,35 +68,6 @@ LL | let i = m!(); | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) -error: 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 - | - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0425`. -Future incompatibility report: Future breakage diagnostic: -error: 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 - | - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) - diff --git a/tests/ui/macros/macro-in-expression-context.fixed b/tests/ui/macros/macro-in-expression-context.fixed index 1d767266025f5..cd1e98365c26e 100644 --- a/tests/ui/macros/macro-in-expression-context.fixed +++ b/tests/ui/macros/macro-in-expression-context.fixed @@ -3,25 +3,13 @@ macro_rules! foo { () => { assert_eq!("A", "A"); - //~^ ERROR trailing semicolon in macro - //~| WARN this was previously - //~| NOTE macro invocations at the end of a block - //~| NOTE to ignore the value produced by the macro - //~| NOTE for more information - //~| NOTE `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default + //~^ ERROR macro expansion ignores `;` + //~| NOTE the usage of `foo!` is likely invalid in expression context assert_eq!("B", "B"); } - //~^^ ERROR macro expansion ignores `assert_eq` and any tokens following - //~| NOTE the usage of `foo!` is likely invalid in expression context } 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 - //~| NOTE in this expansion - //~| NOTE in this expansion } diff --git a/tests/ui/macros/macro-in-expression-context.rs b/tests/ui/macros/macro-in-expression-context.rs index 0bdead1b48021..a1991e6b93af5 100644 --- a/tests/ui/macros/macro-in-expression-context.rs +++ b/tests/ui/macros/macro-in-expression-context.rs @@ -3,25 +3,13 @@ macro_rules! foo { () => { assert_eq!("A", "A"); - //~^ ERROR trailing semicolon in macro - //~| WARN this was previously - //~| NOTE macro invocations at the end of a block - //~| NOTE to ignore the value produced by the macro - //~| NOTE for more information - //~| NOTE `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default + //~^ ERROR macro expansion ignores `;` + //~| NOTE the usage of `foo!` is likely invalid in expression context assert_eq!("B", "B"); } - //~^^ ERROR macro expansion ignores `assert_eq` and any tokens following - //~| NOTE the usage of `foo!` is likely invalid in expression context } 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 - //~| NOTE in this expansion - //~| NOTE in this expansion } diff --git a/tests/ui/macros/macro-in-expression-context.stderr b/tests/ui/macros/macro-in-expression-context.stderr index 27d9490809a99..151bedcd01b28 100644 --- a/tests/ui/macros/macro-in-expression-context.stderr +++ b/tests/ui/macros/macro-in-expression-context.stderr @@ -1,8 +1,8 @@ -error: macro expansion ignores `assert_eq` and any tokens following - --> $DIR/macro-in-expression-context.rs:12:9 +error: macro expansion ignores `;` and any tokens following + --> $DIR/macro-in-expression-context.rs:5:29 | -LL | assert_eq!("B", "B"); - | ^^^^^^^^^ +LL | assert_eq!("A", "A"); + | ^ ... LL | foo!() | ------ caused by the macro expansion here @@ -13,38 +13,5 @@ help: you might be missing a semicolon here LL | foo!(); | + -error: 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: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo` - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -Future incompatibility report: Future breakage diagnostic: -error: 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: macro invocations at the end of a block are treated as expressions - = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo` - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) +error: aborting due to 1 previous error diff --git a/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs b/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs index 6dd9d3d4dee2a..3d26eb0fd6eea 100644 --- a/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs +++ b/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.rs @@ -1,9 +1,9 @@ //@ aux-build:foreign-crate.rs -//@ check-pass +//~? ERROR: macro expansion ignores `;` and any tokens following extern crate foreign_crate; -// Test that we do not lint for a macro in a foreign crate +// Test that we fail with a macro in a foreign crate fn main() { let _ = foreign_crate::my_macro!(); } diff --git a/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.stderr b/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.stderr new file mode 100644 index 0000000000000..ed62ed0305429 --- /dev/null +++ b/tests/ui/macros/semicolon-in-expressions-from-macros/foreign-crate.stderr @@ -0,0 +1,15 @@ +error: macro expansion ignores `;` and any tokens following + --> $DIR/auxiliary/foreign-crate.rs:3:17 + | +LL | () => { true; } + | ^ + | + ::: $DIR/foreign-crate.rs:8:13 + | +LL | let _ = foreign_crate::my_macro!(); + | -------------------------- caused by the macro expansion here + | + = note: the usage of `my_macro!` is likely invalid in expression context + +error: aborting due to 1 previous error + diff --git a/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs index 8ec70a17864ab..48672abad4a22 100644 --- a/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs +++ b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.rs @@ -1,9 +1,8 @@ -// Ensure that trailing semicolons cause errors by default +// Ensure that trailing semicolons cause errors macro_rules! foo { () => { - true; //~ ERROR trailing semicolon in macro - //~| WARN this was previously + true; //~ ERROR macro expansion ignores `;` and any tokens following } } diff --git a/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr index 9506d702f51f1..c1837940b157e 100644 --- a/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr +++ b/tests/ui/macros/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr @@ -1,31 +1,17 @@ -error: trailing semicolon in macro used in expression position +error: macro expansion ignores `;` and any tokens following --> $DIR/warn-semicolon-in-expressions-from-macros.rs:5:13 | LL | true; | ^ ... LL | _ => foo!() - | ------ in this macro invocation + | ------ caused by the macro expansion here | - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: the usage of `foo!` is likely invalid in expression context +help: you might be missing a semicolon here + | +LL | _ => foo!(); + | + error: aborting due to 1 previous error -Future incompatibility report: Future breakage diagnostic: -error: trailing semicolon in macro used in expression position - --> $DIR/warn-semicolon-in-expressions-from-macros.rs:5:13 - | -LL | true; - | ^ -... -LL | _ => foo!() - | ------ in this macro invocation - | - = 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: `#[deny(semicolon_in_expressions_from_macros)]` (part of `#[deny(future_incompatible)]`) on by default - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - diff --git a/tests/ui/macros/trace_faulty_macros.rs b/tests/ui/macros/trace_faulty_macros.rs index e0cbbd8f5c9e6..ff8077cd46d45 100644 --- a/tests/ui/macros/trace_faulty_macros.rs +++ b/tests/ui/macros/trace_faulty_macros.rs @@ -10,7 +10,7 @@ macro_rules! my_faulty_macro { macro_rules! pat_macro { () => { - pat_macro!(A{a:a, b:0, c:_, ..}); + pat_macro!(A{a:a, b:0, c:_, ..}); //~ ERROR macro expansion ignores `;` }; ($a:pat) => { $a //~ ERROR expected expression diff --git a/tests/ui/macros/trace_faulty_macros.stderr b/tests/ui/macros/trace_faulty_macros.stderr index e90d7a98db4c7..60b7a1f3468f0 100644 --- a/tests/ui/macros/trace_faulty_macros.stderr +++ b/tests/ui/macros/trace_faulty_macros.stderr @@ -50,6 +50,17 @@ LL | my_recursive_macro!(); = note: expanding `my_recursive_macro! { }` = note: to `my_recursive_macro! ();` +error: macro expansion ignores `;` and any tokens following + --> $DIR/trace_faulty_macros.rs:13:41 + | +LL | pat_macro!(A{a:a, b:0, c:_, ..}); + | ^ +... +LL | let a = pat_macro!(); + | ------------ caused by the macro expansion here + | + = note: the usage of `pat_macro!` is likely invalid in expression context + error: expected expression, found `pat` metavariable --> $DIR/trace_faulty_macros.rs:16:9 | @@ -102,6 +113,6 @@ LL | test!(let x = 1+1); = note: expanding `test! { (x, 1+1) }` = note: to `let x = 1+1;` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0774`. diff --git a/tests/ui/proc-macro/expand-expr.rs b/tests/ui/proc-macro/expand-expr.rs index c3dddd8e45940..924954400588e 100644 --- a/tests/ui/proc-macro/expand-expr.rs +++ b/tests/ui/proc-macro/expand-expr.rs @@ -115,7 +115,7 @@ expand_expr_fail!(echo_pm!($)); //~ ERROR: expected expression, found `$` // We get errors reported and recover during macro expansion if the macro // doesn't produce a valid expression. -expand_expr_is!("string", echo_tts!("string"; hello)); //~ ERROR: macro expansion ignores `hello` and any tokens following +expand_expr_is!("string", echo_tts!("string"; hello)); //~ ERROR: macro expansion ignores `;` and any tokens following expand_expr_is!("string", echo_pm!("string"; hello)); //~ ERROR: macro expansion ignores `;` and any tokens following // For now, fail if a non-literal expression is expanded. diff --git a/tests/ui/proc-macro/expand-expr.stderr b/tests/ui/proc-macro/expand-expr.stderr index fd5f672adf5c0..ad7add3b0b090 100644 --- a/tests/ui/proc-macro/expand-expr.stderr +++ b/tests/ui/proc-macro/expand-expr.stderr @@ -22,11 +22,11 @@ error: expected expression, found `$` LL | expand_expr_fail!(echo_pm!($)); | ^ expected expression -error: macro expansion ignores `hello` and any tokens following - --> $DIR/expand-expr.rs:118:47 +error: macro expansion ignores `;` and any tokens following + --> $DIR/expand-expr.rs:118:45 | LL | expand_expr_is!("string", echo_tts!("string"; hello)); - | --------------------^^^^^- caused by the macro expansion here + | ------------------^------- caused by the macro expansion here | = note: the usage of `echo_tts!` is likely invalid in expression context help: you might be missing a semicolon here