Skip to content

Commit 55d6c06

Browse files
Properly check arguments of #[coverage]
1 parent f150dbb commit 55d6c06

3 files changed

Lines changed: 53 additions & 14 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
@@ -80,7 +80,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
8080
let mut fail_incorrect_argument =
8181
|span| cx.adcx().expected_specific_argument(span, &[sym::on, sym::off]);
8282

83-
let Some(arg) = arg.meta_item() else {
83+
let Some(arg) = arg.meta_item_no_args() else {
8484
fail_incorrect_argument(arg.span());
8585
return None;
8686
};

tests/ui/attributes/args-checked.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(rustc_attrs)]
22
#![feature(optimize_attribute)]
3+
#![feature(coverage_attribute)]
34
#![allow(unused_attributes)]
45

56
#[inline(always = 5)]
@@ -14,6 +15,10 @@
1415
//~^ ERROR malformed
1516
#[optimize(size(x, y, z))]
1617
//~^ ERROR malformed
18+
#[coverage(off = 5)]
19+
//~^ ERROR malformed
20+
#[coverage(off(x, y, z))]
21+
//~^ ERROR malformed
1722
fn main() {
1823

1924
}

tests/ui/attributes/args-checked.stderr

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0539]: malformed `inline` attribute input
2-
--> $DIR/args-checked.rs:5:1
2+
--> $DIR/args-checked.rs:6:1
33
|
44
LL | #[inline(always = 5)]
55
| ^^^^^^^^^----------^^
@@ -20,7 +20,7 @@ LL + #[inline]
2020
|
2121

2222
error[E0539]: malformed `inline` attribute input
23-
--> $DIR/args-checked.rs:7:1
23+
--> $DIR/args-checked.rs:8:1
2424
|
2525
LL | #[inline(always(x, y, z))]
2626
| ^^^^^^^^^---------------^^
@@ -41,7 +41,7 @@ LL + #[inline]
4141
|
4242

4343
error[E0539]: malformed `instruction_set` attribute input
44-
--> $DIR/args-checked.rs:9:1
44+
--> $DIR/args-checked.rs:10:1
4545
|
4646
LL | #[instruction_set(arm::a32 = 5)]
4747
| ^^^^^^^^^^^^^^^^^^------------^^
@@ -52,7 +52,7 @@ LL | #[instruction_set(arm::a32 = 5)]
5252
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>
5353

5454
error[E0539]: malformed `instruction_set` attribute input
55-
--> $DIR/args-checked.rs:11:1
55+
--> $DIR/args-checked.rs:12:1
5656
|
5757
LL | #[instruction_set(arm::a32(x, y, z))]
5858
| ^^^^^^^^^^^^^^^^^^-----------------^^
@@ -63,7 +63,7 @@ LL | #[instruction_set(arm::a32(x, y, z))]
6363
= note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute>
6464

6565
error[E0539]: malformed `optimize` attribute input
66-
--> $DIR/args-checked.rs:13:1
66+
--> $DIR/args-checked.rs:14:1
6767
|
6868
LL | #[optimize(size = 5)]
6969
| ^^^^^^^^^^^--------^^
@@ -83,7 +83,7 @@ LL + #[optimize(speed)]
8383
|
8484

8585
error[E0539]: malformed `optimize` attribute input
86-
--> $DIR/args-checked.rs:15:1
86+
--> $DIR/args-checked.rs:16:1
8787
|
8888
LL | #[optimize(size(x, y, z))]
8989
| ^^^^^^^^^^^-------------^^
@@ -102,20 +102,54 @@ LL - #[optimize(size(x, y, z))]
102102
LL + #[optimize(speed)]
103103
|
104104

105+
error[E0539]: malformed `coverage` attribute input
106+
--> $DIR/args-checked.rs:18:1
107+
|
108+
LL | #[coverage(off = 5)]
109+
| ^^^^^^^^^^^-------^^
110+
| |
111+
| valid arguments are `on` or `off`
112+
|
113+
help: try changing it to one of the following valid forms of the attribute
114+
|
115+
LL - #[coverage(off = 5)]
116+
LL + #[coverage(off)]
117+
|
118+
LL - #[coverage(off = 5)]
119+
LL + #[coverage(on)]
120+
|
121+
122+
error[E0539]: malformed `coverage` attribute input
123+
--> $DIR/args-checked.rs:20:1
124+
|
125+
LL | #[coverage(off(x, y, z))]
126+
| ^^^^^^^^^^^------------^^
127+
| |
128+
| valid arguments are `on` or `off`
129+
|
130+
help: try changing it to one of the following valid forms of the attribute
131+
|
132+
LL - #[coverage(off(x, y, z))]
133+
LL + #[coverage(off)]
134+
|
135+
LL - #[coverage(off(x, y, z))]
136+
LL + #[coverage(on)]
137+
|
138+
105139
error: `rustc_allow_const_fn_unstable` expects feature names
106-
--> $DIR/args-checked.rs:31:33
140+
--> $DIR/args-checked.rs:36:33
107141
|
108142
LL | #[rustc_allow_const_fn_unstable(x = 5)]
109143
| ^^^^^
110144

111145
error: `rustc_allow_const_fn_unstable` expects feature names
112-
--> $DIR/args-checked.rs:33:33
146+
--> $DIR/args-checked.rs:38:33
113147
|
114148
LL | #[rustc_allow_const_fn_unstable(x(x, y, z))]
115149
| ^^^^^^^^^^
116150

117151
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
118-
--> $DIR/args-checked.rs:21:1
152+
--> $DIR/args-checked.rs:26:1
119153
|
120154
LL | #[macro_export(local_inner_macros = 5)]
121155
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -125,20 +159,20 @@ LL | #[macro_export(local_inner_macros = 5)]
125159
= note: `#[deny(invalid_macro_export_arguments)]` (part of `#[deny(future_incompatible)]`) on by default
126160

127161
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
128-
--> $DIR/args-checked.rs:24:1
162+
--> $DIR/args-checked.rs:29:1
129163
|
130164
LL | #[macro_export(local_inner_macros(x, y, z))]
131165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132166
|
133167
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
134168
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
135169

136-
error: aborting due to 10 previous errors
170+
error: aborting due to 12 previous errors
137171

138172
For more information about this error, try `rustc --explain E0539`.
139173
Future incompatibility report: Future breakage diagnostic:
140174
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
141-
--> $DIR/args-checked.rs:21:1
175+
--> $DIR/args-checked.rs:26:1
142176
|
143177
LL | #[macro_export(local_inner_macros = 5)]
144178
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -149,7 +183,7 @@ LL | #[macro_export(local_inner_macros = 5)]
149183

150184
Future breakage diagnostic:
151185
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
152-
--> $DIR/args-checked.rs:24:1
186+
--> $DIR/args-checked.rs:29:1
153187
|
154188
LL | #[macro_export(local_inner_macros(x, y, z))]
155189
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)