Skip to content

Commit 8e382ba

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 8e382ba

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

Diff for: 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
}

Diff for: tests/crashes/127880.rs

-5
This file was deleted.

Diff for: tests/ui/coverage-attr/bad-attr-ice.feat.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: malformed `coverage` attribute input
2+
--> $DIR/bad-attr-ice.rs:10: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+

Diff for: tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: malformed `coverage` attribute input
2+
--> $DIR/bad-attr-ice.rs:10: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:10: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`.

Diff for: tests/ui/coverage-attr/bad-attr-ice.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![cfg_attr(feat, feature(coverage_attribute))]
2+
//@ revisions: feat nofeat
3+
//@ compile-flags: -Cinstrument-coverage
4+
//@ needs-profiler-support
5+
6+
// Malformed `#[coverage(..)]` attributes should not cause an ICE when built
7+
// with `-Cinstrument-coverage`.
8+
// Regression test for <https://github.com/rust-lang/rust/issues/127880>.
9+
10+
#[coverage]
11+
//~^ ERROR malformed `coverage` attribute input
12+
//[nofeat]~| the `#[coverage]` attribute is an experimental feature
13+
fn main() {}
14+
15+
// FIXME(#130766): When the `#[coverage(..)]` attribute is stabilized,
16+
// get rid of the revisions and just make this a normal test.

0 commit comments

Comments
 (0)