Skip to content

Commit bd3323d

Browse files
committed
More status-quo tests for the #[coverage(..)] attribute
These tests reveal some inconsistencies that are tracked by <#126658>.
1 parent 8fcd4dd commit bd3323d

File tree

5 files changed

+390
-4
lines changed

5 files changed

+390
-4
lines changed

tests/ui/coverage-attr/bad-syntax.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// Tests the error messages produced (or not produced) by various unusual
44
// uses of the `#[coverage(..)]` attribute.
55

6-
// FIXME(#84605): Multiple coverage attributes with the same value are useless,
6+
// FIXME(#126658): Multiple coverage attributes with the same value are useless,
77
// and should probably produce a diagnostic.
88
#[coverage(off)]
99
#[coverage(off)]
1010
fn multiple_consistent() {}
1111

12-
// FIXME(#84605): When there are multiple inconsistent coverage attributes,
12+
// FIXME(#126658): When there are multiple inconsistent coverage attributes,
1313
// it's unclear which one will prevail.
1414
#[coverage(off)]
1515
#[coverage(on)]
@@ -18,7 +18,7 @@ fn multiple_inconsistent() {}
1818
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
1919
fn bare_word() {}
2020

21-
// FIXME(#84605): This shows as multiple different errors, one of which suggests
21+
// FIXME(#126658): This shows as multiple different errors, one of which suggests
2222
// writing bare `#[coverage]`, which is not allowed.
2323
#[coverage = true]
2424
//~^ ERROR expected `coverage(off)` or `coverage(on)`
@@ -48,7 +48,7 @@ fn bogus_word_after() {}
4848
#[coverage(off,)]
4949
fn comma_after() {}
5050

51-
// FIXME(#84605): This shows as multiple different errors.
51+
// FIXME(#126658): This shows as multiple different errors.
5252
#[coverage(,off)]
5353
//~^ ERROR expected identifier, found `,`
5454
//~| HELP remove this comma

tests/ui/coverage-attr/name-value.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
4+
// Demonstrates the diagnostics produced when using the syntax
5+
// `#![coverage = "off"]`, which should not be allowed.
6+
7+
// FIXME(#126658): The error messages for using this syntax are inconsistent
8+
// with the error message in other cases. They also sometimes appear together
9+
// with other errors, and they suggest using the incorrect `#[coverage]` syntax.
10+
11+
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
12+
mod my_mod {}
13+
14+
mod my_mod_inner {
15+
#![coverage = "off"] //~ ERROR malformed `coverage` attribute input
16+
}
17+
18+
#[coverage = "off"]
19+
//~^ ERROR `#[coverage]` must be applied to coverable code
20+
//~| ERROR malformed `coverage` attribute input
21+
struct MyStruct;
22+
23+
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
24+
impl MyStruct {
25+
#[coverage = "off"]
26+
//~^ ERROR `#[coverage]` must be applied to coverable code
27+
//~| ERROR malformed `coverage` attribute input
28+
const X: u32 = 7;
29+
}
30+
31+
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
32+
trait MyTrait {
33+
#[coverage = "off"]
34+
//~^ ERROR `#[coverage]` must be applied to coverable code
35+
//~| ERROR malformed `coverage` attribute input
36+
const X: u32;
37+
38+
#[coverage = "off"]
39+
//~^ ERROR `#[coverage]` must be applied to coverable code
40+
//~| ERROR malformed `coverage` attribute input
41+
type T;
42+
}
43+
44+
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
45+
impl MyTrait for MyStruct {
46+
#[coverage = "off"]
47+
//~^ ERROR `#[coverage]` must be applied to coverable code
48+
//~| ERROR malformed `coverage` attribute input
49+
const X: u32 = 8;
50+
51+
#[coverage = "off"]
52+
//~^ ERROR `#[coverage]` must be applied to coverable code
53+
//~| ERROR malformed `coverage` attribute input
54+
type T = ();
55+
}
56+
57+
#[coverage = "off"]
58+
//~^ ERROR expected `coverage(off)` or `coverage(on)`
59+
//~| ERROR malformed `coverage` attribute input
60+
fn main() {}
+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
error: malformed `coverage` attribute input
2+
--> $DIR/name-value.rs:11:1
3+
|
4+
LL | #[coverage = "off"]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[coverage(on|off)]
10+
| ~~~~~~~~~~~~~~~~~~~
11+
LL | #[coverage]
12+
| ~~~~~~~~~~~
13+
14+
error: malformed `coverage` attribute input
15+
--> $DIR/name-value.rs:15:5
16+
|
17+
LL | #![coverage = "off"]
18+
| ^^^^^^^^^^^^^^^^^^^^
19+
|
20+
help: the following are the possible correct uses
21+
|
22+
LL | #![coverage(on|off)]
23+
| ~~~~~~~~~~~~~~~~~~~~
24+
LL | #![coverage]
25+
| ~~~~~~~~~~~~
26+
27+
error: malformed `coverage` attribute input
28+
--> $DIR/name-value.rs:18:1
29+
|
30+
LL | #[coverage = "off"]
31+
| ^^^^^^^^^^^^^^^^^^^
32+
|
33+
help: the following are the possible correct uses
34+
|
35+
LL | #[coverage(on|off)]
36+
|
37+
LL | #[coverage]
38+
|
39+
40+
error: malformed `coverage` attribute input
41+
--> $DIR/name-value.rs:25:5
42+
|
43+
LL | #[coverage = "off"]
44+
| ^^^^^^^^^^^^^^^^^^^
45+
|
46+
help: the following are the possible correct uses
47+
|
48+
LL | #[coverage(on|off)]
49+
|
50+
LL | #[coverage]
51+
|
52+
53+
error: malformed `coverage` attribute input
54+
--> $DIR/name-value.rs:23:1
55+
|
56+
LL | #[coverage = "off"]
57+
| ^^^^^^^^^^^^^^^^^^^
58+
|
59+
help: the following are the possible correct uses
60+
|
61+
LL | #[coverage(on|off)]
62+
| ~~~~~~~~~~~~~~~~~~~
63+
LL | #[coverage]
64+
| ~~~~~~~~~~~
65+
66+
error: malformed `coverage` attribute input
67+
--> $DIR/name-value.rs:33:5
68+
|
69+
LL | #[coverage = "off"]
70+
| ^^^^^^^^^^^^^^^^^^^
71+
|
72+
help: the following are the possible correct uses
73+
|
74+
LL | #[coverage(on|off)]
75+
|
76+
LL | #[coverage]
77+
|
78+
79+
error: malformed `coverage` attribute input
80+
--> $DIR/name-value.rs:38:5
81+
|
82+
LL | #[coverage = "off"]
83+
| ^^^^^^^^^^^^^^^^^^^
84+
|
85+
help: the following are the possible correct uses
86+
|
87+
LL | #[coverage(on|off)]
88+
|
89+
LL | #[coverage]
90+
|
91+
92+
error: malformed `coverage` attribute input
93+
--> $DIR/name-value.rs:31:1
94+
|
95+
LL | #[coverage = "off"]
96+
| ^^^^^^^^^^^^^^^^^^^
97+
|
98+
help: the following are the possible correct uses
99+
|
100+
LL | #[coverage(on|off)]
101+
| ~~~~~~~~~~~~~~~~~~~
102+
LL | #[coverage]
103+
| ~~~~~~~~~~~
104+
105+
error: malformed `coverage` attribute input
106+
--> $DIR/name-value.rs:46:5
107+
|
108+
LL | #[coverage = "off"]
109+
| ^^^^^^^^^^^^^^^^^^^
110+
|
111+
help: the following are the possible correct uses
112+
|
113+
LL | #[coverage(on|off)]
114+
|
115+
LL | #[coverage]
116+
|
117+
118+
error: malformed `coverage` attribute input
119+
--> $DIR/name-value.rs:51:5
120+
|
121+
LL | #[coverage = "off"]
122+
| ^^^^^^^^^^^^^^^^^^^
123+
|
124+
help: the following are the possible correct uses
125+
|
126+
LL | #[coverage(on|off)]
127+
|
128+
LL | #[coverage]
129+
|
130+
131+
error: malformed `coverage` attribute input
132+
--> $DIR/name-value.rs:44:1
133+
|
134+
LL | #[coverage = "off"]
135+
| ^^^^^^^^^^^^^^^^^^^
136+
|
137+
help: the following are the possible correct uses
138+
|
139+
LL | #[coverage(on|off)]
140+
| ~~~~~~~~~~~~~~~~~~~
141+
LL | #[coverage]
142+
| ~~~~~~~~~~~
143+
144+
error: malformed `coverage` attribute input
145+
--> $DIR/name-value.rs:57:1
146+
|
147+
LL | #[coverage = "off"]
148+
| ^^^^^^^^^^^^^^^^^^^
149+
|
150+
help: the following are the possible correct uses
151+
|
152+
LL | #[coverage(on|off)]
153+
|
154+
LL | #[coverage]
155+
|
156+
157+
error[E0788]: `#[coverage]` must be applied to coverable code
158+
--> $DIR/name-value.rs:18:1
159+
|
160+
LL | #[coverage = "off"]
161+
| ^^^^^^^^^^^^^^^^^^^
162+
...
163+
LL | struct MyStruct;
164+
| ---------------- not coverable code
165+
166+
error[E0788]: `#[coverage]` must be applied to coverable code
167+
--> $DIR/name-value.rs:33:5
168+
|
169+
LL | #[coverage = "off"]
170+
| ^^^^^^^^^^^^^^^^^^^
171+
...
172+
LL | const X: u32;
173+
| ------------- not coverable code
174+
175+
error[E0788]: `#[coverage]` must be applied to coverable code
176+
--> $DIR/name-value.rs:38:5
177+
|
178+
LL | #[coverage = "off"]
179+
| ^^^^^^^^^^^^^^^^^^^
180+
...
181+
LL | type T;
182+
| ------- not coverable code
183+
184+
error[E0788]: `#[coverage]` must be applied to coverable code
185+
--> $DIR/name-value.rs:25:5
186+
|
187+
LL | #[coverage = "off"]
188+
| ^^^^^^^^^^^^^^^^^^^
189+
...
190+
LL | const X: u32 = 7;
191+
| ----------------- not coverable code
192+
193+
error[E0788]: `#[coverage]` must be applied to coverable code
194+
--> $DIR/name-value.rs:46:5
195+
|
196+
LL | #[coverage = "off"]
197+
| ^^^^^^^^^^^^^^^^^^^
198+
...
199+
LL | const X: u32 = 8;
200+
| ----------------- not coverable code
201+
202+
error[E0788]: `#[coverage]` must be applied to coverable code
203+
--> $DIR/name-value.rs:51:5
204+
|
205+
LL | #[coverage = "off"]
206+
| ^^^^^^^^^^^^^^^^^^^
207+
...
208+
LL | type T = ();
209+
| ------------ not coverable code
210+
211+
error: expected `coverage(off)` or `coverage(on)`
212+
--> $DIR/name-value.rs:57:1
213+
|
214+
LL | #[coverage = "off"]
215+
| ^^^^^^^^^^^^^^^^^^^
216+
217+
error: aborting due to 19 previous errors
218+
219+
For more information about this error, try `rustc --explain E0788`.

tests/ui/coverage-attr/word-only.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
4+
// Demonstrates the diagnostics produced when using the syntax `#![coverage]`,
5+
// which should not be allowed.
6+
7+
// FIXME(#126658): The error messages for using this syntax give the impression
8+
// that it is legal, even though it should never be legal.
9+
10+
// FIXME(#126658): This is silently allowed, but should not be.
11+
#[coverage]
12+
mod my_mod {}
13+
14+
// FIXME(#126658): This is silently allowed, but should not be.
15+
mod my_mod_inner {
16+
#![coverage]
17+
}
18+
19+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
20+
struct MyStruct;
21+
22+
// FIXME(#126658): This is silently allowed, but should not be.
23+
#[coverage]
24+
impl MyStruct {
25+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
26+
const X: u32 = 7;
27+
}
28+
29+
// FIXME(#126658): This is silently allowed, but should not be.
30+
#[coverage]
31+
trait MyTrait {
32+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
33+
const X: u32;
34+
35+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
36+
type T;
37+
}
38+
39+
// FIXME(#126658): This is silently allowed, but should not be.
40+
#[coverage]
41+
impl MyTrait for MyStruct {
42+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
43+
const X: u32 = 8;
44+
45+
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
46+
type T = ();
47+
}
48+
49+
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
50+
fn main() {}

0 commit comments

Comments
 (0)