Skip to content

Commit 6d24063

Browse files
committed
coverage: Forbid multiple #[coverage(..)] attributes
It might make sense to allow this in the future, if we add values that aren't mutually exclusive, but for now having multiple coverage attributes on one item is useless.
1 parent ebb3aa0 commit 6d24063

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
479479
),
480480
gated!(
481481
coverage, Normal, template!(Word, List: "on|off"),
482-
WarnFollowing, EncodeCrossCrate::No,
482+
ErrorPreceding, EncodeCrossCrate::No,
483483
coverage_attribute, experimental!(coverage)
484484
),
485485

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

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

6-
// FIXME(#126658): Multiple coverage attributes with the same value are useless,
7-
// and should probably produce a diagnostic.
86
#[coverage(off)]
7+
//~^ ERROR multiple `coverage` attributes
8+
//~| HELP remove this attribute
99
#[coverage(off)]
1010
fn multiple_consistent() {}
1111

12-
// FIXME(#126658): When there are multiple inconsistent coverage attributes,
13-
// it's unclear which one will prevail.
1412
#[coverage(off)]
13+
//~^ ERROR multiple `coverage` attributes
14+
//~| HELP remove this attribute
1515
#[coverage(on)]
1616
fn multiple_inconsistent() {}
1717

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ LL | #[coverage(,off)]
2020
| expected identifier
2121
| help: remove this comma
2222

23+
error: multiple `coverage` attributes
24+
--> $DIR/bad-syntax.rs:6:1
25+
|
26+
LL | #[coverage(off)]
27+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
28+
|
29+
note: attribute also specified here
30+
--> $DIR/bad-syntax.rs:9:1
31+
|
32+
LL | #[coverage(off)]
33+
| ^^^^^^^^^^^^^^^^
34+
35+
error: multiple `coverage` attributes
36+
--> $DIR/bad-syntax.rs:12:1
37+
|
38+
LL | #[coverage(off)]
39+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
40+
|
41+
note: attribute also specified here
42+
--> $DIR/bad-syntax.rs:15:1
43+
|
44+
LL | #[coverage(on)]
45+
| ^^^^^^^^^^^^^^^
46+
2347
error: expected `coverage(off)` or `coverage(on)`
2448
--> $DIR/bad-syntax.rs:18:1
2549
|
@@ -74,5 +98,5 @@ error: expected `coverage(off)` or `coverage(on)`
7498
LL | #[coverage(,off)]
7599
| ^^^^^^^^^^^^^^^^^
76100

77-
error: aborting due to 11 previous errors
101+
error: aborting due to 13 previous errors
78102

0 commit comments

Comments
 (0)