Skip to content

Commit f3b5343

Browse files
committed
Avoid ICE in coverage builds with bad #[coverage(..)] attributes
This code can sometimes witness malformed coverage attributes in builds that are going to fail, so use `span_delayed_bug` to avoid an inappropriate ICE in that case.
1 parent ad9c494 commit f3b5343

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

compiler/rustc_mir_transform/src/coverage/query.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
6363
Some([item]) if item.has_name(sym::on) => return true,
6464
Some(_) | None => {
6565
// Other possibilities should have been rejected by `rustc_parse::validate_attr`.
66-
tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute");
66+
// Use `span_delayed_bug` to avoid an ICE in failing builds (#127880).
67+
tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute");
6768
}
6869
}
6970
}

tests/crashes/127880.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: malformed `coverage` attribute input
2+
--> $DIR/bad-attr-ice.rs:9:1
3+
|
4+
LL | #[coverage]
5+
| ^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[coverage(off)]
10+
|
11+
LL | #[coverage(on)]
12+
|
13+
14+
error: aborting due to 1 previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: malformed `coverage` attribute input
2+
--> $DIR/bad-attr-ice.rs:9:1
3+
|
4+
LL | #[coverage]
5+
| ^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[coverage(off)]
10+
|
11+
LL | #[coverage(on)]
12+
|
13+
14+
error[E0658]: the `#[coverage]` attribute is an experimental feature
15+
--> $DIR/bad-attr-ice.rs:9:1
16+
|
17+
LL | #[coverage]
18+
| ^^^^^^^^^^^
19+
|
20+
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
21+
= help: add `#![feature(coverage_attribute)]` to the crate attributes to enable
22+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0658`.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![cfg_attr(feat, feature(coverage_attribute))]
2+
//@ revisions: feat nofeat
3+
//@ compile-flags: -Cinstrument-coverage
4+
5+
// Malformed `#[coverage(..)]` attributes should not cause an ICE when built
6+
// with `-Cinstrument-coverage`.
7+
// Regression test for <https://github.com/rust-lang/rust/issues/127880>.
8+
9+
#[coverage]
10+
//~^ ERROR malformed `coverage` attribute input
11+
//[nofeat]~| the `#[coverage]` attribute is an experimental feature
12+
fn main() {}
13+
14+
// FIXME(#130766): When the `#[coverage(..)]` attribute is stabilized,
15+
// get rid of the revisions and just make this a normal test.

0 commit comments

Comments
 (0)