Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICE in coverage builds with bad #[coverage(..)] attributes #131187

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/coverage/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
Some([item]) if item.has_name(sym::on) => return true,
Some(_) | None => {
// Other possibilities should have been rejected by `rustc_parse::validate_attr`.
tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute");
// Use `span_delayed_bug` to avoid an ICE in failing builds (#127880).
tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute");
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions tests/crashes/127880.rs

This file was deleted.

15 changes: 15 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.feat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: malformed `coverage` attribute input
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|

error: aborting due to 1 previous error

26 changes: 26 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: malformed `coverage` attribute input
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|

error[E0658]: the `#[coverage]` attribute is an experimental feature
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
= help: add `#![feature(coverage_attribute)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
16 changes: 16 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![cfg_attr(feat, feature(coverage_attribute))]
//@ revisions: feat nofeat
//@ compile-flags: -Cinstrument-coverage
//@ needs-profiler-support

// Malformed `#[coverage(..)]` attributes should not cause an ICE when built
// with `-Cinstrument-coverage`.
// Regression test for <https://github.com/rust-lang/rust/issues/127880>.

#[coverage]
//~^ ERROR malformed `coverage` attribute input
//[nofeat]~| the `#[coverage]` attribute is an experimental feature
fn main() {}

// FIXME(#130766): When the `#[coverage(..)]` attribute is stabilized,
// get rid of the revisions and just make this a normal test.
Loading