Skip to content

Commit 52d9d60

Browse files
committed
Auto merge of #155091 - JonathanBrouwer:fix-macro-export, r=<try>
Reject arguments to `local_inner_macros` for `#[macro_export]`
2 parents 25a54d4 + b8d19ad commit 52d9d60

4 files changed

Lines changed: 95 additions & 7 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,19 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
146146
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
147147
return None;
148148
};
149-
match l.meta_item().and_then(|i| i.path().word_sym()) {
150-
Some(sym::local_inner_macros) => true,
151-
_ => {
152-
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
153-
return None;
154-
}
149+
let Some(l) = l.meta_item() else {
150+
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
151+
return None;
152+
};
153+
if !l.path().word_is(sym::local_inner_macros) {
154+
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
155+
return None;
156+
}
157+
if let Err(_) = l.args().no_args() {
158+
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
159+
return None;
155160
}
161+
true
156162
}
157163
ArgParser::NameValue(nv) => {
158164
cx.adcx().expected_list_or_no_args(nv.args_span());

tests/ui/attributes/invalid_macro_export_argument.allow.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,23 @@ LL | #[macro_export("blah")]
3838
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3939
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
4040

41+
Future breakage diagnostic:
42+
warning: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
43+
--> $DIR/invalid_macro_export_argument.rs:45:1
44+
|
45+
LL | #[macro_export(local_inner_macros = false)]
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
50+
51+
Future breakage diagnostic:
52+
warning: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
53+
--> $DIR/invalid_macro_export_argument.rs:52:1
54+
|
55+
LL | #[macro_export(local_inner_macros(false))]
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
|
58+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
59+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
60+

tests/ui/attributes/invalid_macro_export_argument.deny.stderr

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,25 @@ LL | #[macro_export("blah")]
3939
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4040
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
4141

42-
error: aborting due to 4 previous errors
42+
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
43+
--> $DIR/invalid_macro_export_argument.rs:45:1
44+
|
45+
LL | #[macro_export(local_inner_macros = false)]
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
50+
51+
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
52+
--> $DIR/invalid_macro_export_argument.rs:52:1
53+
|
54+
LL | #[macro_export(local_inner_macros(false))]
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
58+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
59+
60+
error: aborting due to 6 previous errors
4361

4462
Future incompatibility report: Future breakage diagnostic:
4563
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
101119
LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))]
102120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103121

122+
Future breakage diagnostic:
123+
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
124+
--> $DIR/invalid_macro_export_argument.rs:45:1
125+
|
126+
LL | #[macro_export(local_inner_macros = false)]
127+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128+
|
129+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
130+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
131+
note: the lint level is defined here
132+
--> $DIR/invalid_macro_export_argument.rs:4:24
133+
|
134+
LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))]
135+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136+
137+
Future breakage diagnostic:
138+
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
139+
--> $DIR/invalid_macro_export_argument.rs:52:1
140+
|
141+
LL | #[macro_export(local_inner_macros(false))]
142+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143+
|
144+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
145+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
146+
note: the lint level is defined here
147+
--> $DIR/invalid_macro_export_argument.rs:4:24
148+
|
149+
LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))]
150+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+

tests/ui/attributes/invalid_macro_export_argument.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,18 @@ macro_rules! f {
4242
() => ()
4343
}
4444

45+
#[macro_export(local_inner_macros = false)]
46+
//[deny]~^ ERROR valid forms for the attribute are
47+
//[deny]~| WARN this was previously accepted
48+
macro_rules! g {
49+
() => ()
50+
}
51+
52+
#[macro_export(local_inner_macros(false))]
53+
//[deny]~^ ERROR valid forms for the attribute are
54+
//[deny]~| WARN this was previously accepted
55+
macro_rules! h {
56+
() => ()
57+
}
58+
4559
fn main() {}

0 commit comments

Comments
 (0)