From b8d19ad4796bf05197b41f41e61fb4e9d01893ca Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Fri, 10 Apr 2026 11:57:43 +0200 Subject: [PATCH] Reject arguments to `local_inner_macros` for `#[macro_export]` --- .../src/attributes/macro_attrs.rs | 18 ++++--- ...invalid_macro_export_argument.allow.stderr | 20 ++++++++ .../invalid_macro_export_argument.deny.stderr | 50 ++++++++++++++++++- .../invalid_macro_export_argument.rs | 14 ++++++ 4 files changed, 95 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index 3467d5712e1a2..9a35be8bf6748 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -146,13 +146,19 @@ impl SingleAttributeParser for MacroExportParser { cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS); return None; }; - match l.meta_item().and_then(|i| i.path().word_sym()) { - Some(sym::local_inner_macros) => true, - _ => { - cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS); - return None; - } + let Some(l) = l.meta_item() else { + cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS); + return None; + }; + if !l.path().word_is(sym::local_inner_macros) { + cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS); + return None; + } + if let Err(_) = l.args().no_args() { + cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS); + return None; } + true } ArgParser::NameValue(nv) => { cx.adcx().expected_list_or_no_args(nv.args_span()); diff --git a/tests/ui/attributes/invalid_macro_export_argument.allow.stderr b/tests/ui/attributes/invalid_macro_export_argument.allow.stderr index 2db60a6897282..2b10e8cf8621f 100644 --- a/tests/ui/attributes/invalid_macro_export_argument.allow.stderr +++ b/tests/ui/attributes/invalid_macro_export_argument.allow.stderr @@ -38,3 +38,23 @@ LL | #[macro_export("blah")] = 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 #57571 +Future breakage diagnostic: +warning: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:45:1 + | +LL | #[macro_export(local_inner_macros = false)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 + +Future breakage diagnostic: +warning: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:52:1 + | +LL | #[macro_export(local_inner_macros(false))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 + diff --git a/tests/ui/attributes/invalid_macro_export_argument.deny.stderr b/tests/ui/attributes/invalid_macro_export_argument.deny.stderr index fd50b824d0a26..58a2cc2b2eb77 100644 --- a/tests/ui/attributes/invalid_macro_export_argument.deny.stderr +++ b/tests/ui/attributes/invalid_macro_export_argument.deny.stderr @@ -39,7 +39,25 @@ LL | #[macro_export("blah")] = 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 #57571 -error: aborting due to 4 previous errors +error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:45:1 + | +LL | #[macro_export(local_inner_macros = false)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 + +error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:52:1 + | +LL | #[macro_export(local_inner_macros(false))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 + +error: aborting due to 6 previous errors Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` @@ -101,3 +119,33 @@ note: the lint level is defined here LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Future breakage diagnostic: +error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:45:1 + | +LL | #[macro_export(local_inner_macros = false)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 +note: the lint level is defined here + --> $DIR/invalid_macro_export_argument.rs:4:24 + | +LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` + --> $DIR/invalid_macro_export_argument.rs:52:1 + | +LL | #[macro_export(local_inner_macros(false))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 +note: the lint level is defined here + --> $DIR/invalid_macro_export_argument.rs:4:24 + | +LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/attributes/invalid_macro_export_argument.rs b/tests/ui/attributes/invalid_macro_export_argument.rs index 05a40913434e8..c338e86d5232b 100644 --- a/tests/ui/attributes/invalid_macro_export_argument.rs +++ b/tests/ui/attributes/invalid_macro_export_argument.rs @@ -42,4 +42,18 @@ macro_rules! f { () => () } +#[macro_export(local_inner_macros = false)] +//[deny]~^ ERROR valid forms for the attribute are +//[deny]~| WARN this was previously accepted +macro_rules! g { + () => () +} + +#[macro_export(local_inner_macros(false))] +//[deny]~^ ERROR valid forms for the attribute are +//[deny]~| WARN this was previously accepted +macro_rules! h { + () => () +} + fn main() {}