Skip to content

Commit 76bc7af

Browse files
Properly check arguments of #[used]
1 parent 55d6c06 commit 76bc7af

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
375375
return;
376376
};
377377

378-
match l.meta_item().and_then(|i| i.path().word_sym()) {
378+
match l.meta_item_no_args().and_then(|i| i.path().word_sym()) {
379379
Some(sym::compiler) => {
380380
if !cx.features().used_with_arg() {
381381
feature_err(

tests/ui/attributes/args-checked.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ macro_rules! m {
3737
//~^ ERROR `rustc_allow_const_fn_unstable` expects feature names
3838
#[rustc_allow_const_fn_unstable(x(x, y, z))]
3939
//~^ ERROR `rustc_allow_const_fn_unstable` expects feature names
40-
const fn g() {}
40+
const fn g() {}
41+
42+
#[used(always = 5)]
43+
//~^ ERROR malformed
44+
#[used(always(x, y, z))]
45+
//~^ ERROR malformed
46+
static H: u64 = 5;

tests/ui/attributes/args-checked.stderr

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,46 @@ error: `rustc_allow_const_fn_unstable` expects feature names
148148
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
149149
| ^^^^^^^^^^
150150

151+
error[E0539]: malformed `used` attribute input
152+
--> $DIR/args-checked.rs:42:1
153+
|
154+
LL | #[used(always = 5)]
155+
| ^^^^^^^----------^^
156+
| |
157+
| valid arguments are `compiler` or `linker`
158+
|
159+
help: try changing it to one of the following valid forms of the attribute
160+
|
161+
LL - #[used(always = 5)]
162+
LL + #[used(compiler)]
163+
|
164+
LL - #[used(always = 5)]
165+
LL + #[used(linker)]
166+
|
167+
LL - #[used(always = 5)]
168+
LL + #[used]
169+
|
170+
171+
error[E0539]: malformed `used` attribute input
172+
--> $DIR/args-checked.rs:44:1
173+
|
174+
LL | #[used(always(x, y, z))]
175+
| ^^^^^^^---------------^^
176+
| |
177+
| valid arguments are `compiler` or `linker`
178+
|
179+
help: try changing it to one of the following valid forms of the attribute
180+
|
181+
LL - #[used(always(x, y, z))]
182+
LL + #[used(compiler)]
183+
|
184+
LL - #[used(always(x, y, z))]
185+
LL + #[used(linker)]
186+
|
187+
LL - #[used(always(x, y, z))]
188+
LL + #[used]
189+
|
190+
151191
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
152192
--> $DIR/args-checked.rs:26:1
153193
|
@@ -167,7 +207,7 @@ LL | #[macro_export(local_inner_macros(x, y, z))]
167207
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
168208
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
169209

170-
error: aborting due to 12 previous errors
210+
error: aborting due to 14 previous errors
171211

172212
For more information about this error, try `rustc --explain E0539`.
173213
Future incompatibility report: Future breakage diagnostic:

0 commit comments

Comments
 (0)