Auto merge of #84562 - richkadel:issue-83601, r=tmandry
Adds feature-gated `#[no_coverage]` function attribute, to fix derived Eq `0` coverage issue #83601 Derived Eq no longer shows uncovered The Eq trait has a special hidden function. MIR `InstrumentCoverage` would add this function to the coverage map, but it is never called, so the `Eq` trait would always appear uncovered. Fixes: #83601 The fix required creating a new function attribute `no_coverage` to mark functions that should be ignored by `InstrumentCoverage` and the coverage `mapgen` (during codegen). Adding a `no_coverage` feature gate with tracking issue #84605. r? `@tmandry` cc: `@wesleywiser`
This commit is contained in:
commit
20040fa332
18 changed files with 198 additions and 2 deletions
|
|
@ -0,0 +1,22 @@
|
|||
1| |// Shows that rust-lang/rust/83601 is resolved
|
||||
2| |
|
||||
3| 3|#[derive(Debug, PartialEq, Eq)]
|
||||
^2
|
||||
------------------
|
||||
| <issue_83601::Foo as core::cmp::PartialEq>::eq:
|
||||
| 3| 2|#[derive(Debug, PartialEq, Eq)]
|
||||
------------------
|
||||
| Unexecuted instantiation: <issue_83601::Foo as core::cmp::PartialEq>::ne
|
||||
------------------
|
||||
4| |struct Foo(u32);
|
||||
5| |
|
||||
6| 1|fn main() {
|
||||
7| 1| let bar = Foo(1);
|
||||
8| 0| assert_eq!(bar, Foo(1));
|
||||
9| 1| let baz = Foo(0);
|
||||
10| 0| assert_ne!(baz, Foo(1));
|
||||
11| 1| println!("{:?}", Foo(1));
|
||||
12| 1| println!("{:?}", bar);
|
||||
13| 1| println!("{:?}", baz);
|
||||
14| 1|}
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
1| |// Enables `no_coverage` on the entire crate
|
||||
2| |#![feature(no_coverage)]
|
||||
3| |
|
||||
4| |#[no_coverage]
|
||||
5| |fn do_not_add_coverage_1() {
|
||||
6| | println!("called but not covered");
|
||||
7| |}
|
||||
8| |
|
||||
9| |#[no_coverage]
|
||||
10| |fn do_not_add_coverage_2() {
|
||||
11| | println!("called but not covered");
|
||||
12| |}
|
||||
13| |
|
||||
14| 1|fn main() {
|
||||
15| 1| do_not_add_coverage_1();
|
||||
16| 1| do_not_add_coverage_2();
|
||||
17| 1|}
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
1| |// Enables `no_coverage` on individual functions
|
||||
2| |
|
||||
3| |#[feature(no_coverage)]
|
||||
4| |#[no_coverage]
|
||||
5| |fn do_not_add_coverage_1() {
|
||||
6| | println!("called but not covered");
|
||||
7| |}
|
||||
8| |
|
||||
9| |#[no_coverage]
|
||||
10| |#[feature(no_coverage)]
|
||||
11| |fn do_not_add_coverage_2() {
|
||||
12| | println!("called but not covered");
|
||||
13| |}
|
||||
14| |
|
||||
15| 1|fn main() {
|
||||
16| 1| do_not_add_coverage_1();
|
||||
17| 1| do_not_add_coverage_2();
|
||||
18| 1|}
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
2| |// structure of this test.
|
||||
3| |
|
||||
4| 2|#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
^0 ^0 ^0 ^0 ^1 ^1 ^0^0
|
||||
^0 ^0 ^0 ^1 ^1 ^0^0
|
||||
------------------
|
||||
| Unexecuted instantiation: <partial_eq::Version as core::cmp::PartialEq>::ne
|
||||
------------------
|
||||
|
|
|
|||
14
src/test/run-make-fulldeps/coverage/issue-83601.rs
Normal file
14
src/test/run-make-fulldeps/coverage/issue-83601.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Shows that rust-lang/rust/83601 is resolved
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Foo(u32);
|
||||
|
||||
fn main() {
|
||||
let bar = Foo(1);
|
||||
assert_eq!(bar, Foo(1));
|
||||
let baz = Foo(0);
|
||||
assert_ne!(baz, Foo(1));
|
||||
println!("{:?}", Foo(1));
|
||||
println!("{:?}", bar);
|
||||
println!("{:?}", baz);
|
||||
}
|
||||
17
src/test/run-make-fulldeps/coverage/no_cov_crate.rs
Normal file
17
src/test/run-make-fulldeps/coverage/no_cov_crate.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Enables `no_coverage` on the entire crate
|
||||
#![feature(no_coverage)]
|
||||
|
||||
#[no_coverage]
|
||||
fn do_not_add_coverage_1() {
|
||||
println!("called but not covered");
|
||||
}
|
||||
|
||||
#[no_coverage]
|
||||
fn do_not_add_coverage_2() {
|
||||
println!("called but not covered");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
do_not_add_coverage_1();
|
||||
do_not_add_coverage_2();
|
||||
}
|
||||
18
src/test/run-make-fulldeps/coverage/no_cov_func.rs
Normal file
18
src/test/run-make-fulldeps/coverage/no_cov_func.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Enables `no_coverage` on individual functions
|
||||
|
||||
#[feature(no_coverage)]
|
||||
#[no_coverage]
|
||||
fn do_not_add_coverage_1() {
|
||||
println!("called but not covered");
|
||||
}
|
||||
|
||||
#[no_coverage]
|
||||
#[feature(no_coverage)]
|
||||
fn do_not_add_coverage_2() {
|
||||
println!("called but not covered");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
do_not_add_coverage_1();
|
||||
do_not_add_coverage_2();
|
||||
}
|
||||
8
src/test/ui/feature-gates/feature-gate-no_coverage.rs
Normal file
8
src/test/ui/feature-gates/feature-gate-no_coverage.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#![crate_type = "lib"]
|
||||
|
||||
#[no_coverage]
|
||||
#[feature(no_coverage)] // does not have to be enabled before `#[no_coverage]`
|
||||
fn no_coverage_is_enabled_on_this_function() {}
|
||||
|
||||
#[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature
|
||||
fn requires_feature_no_coverage() {}
|
||||
13
src/test/ui/feature-gates/feature-gate-no_coverage.stderr
Normal file
13
src/test/ui/feature-gates/feature-gate-no_coverage.stderr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
error[E0658]: the `#[no_coverage]` attribute is an experimental feature
|
||||
--> $DIR/feature-gate-no_coverage.rs:7:1
|
||||
|
|
||||
LL | #[no_coverage]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
|
||||
= help: add `#![feature(no_coverage)]` to the crate attributes to enable
|
||||
= help: or, alternatively, add `#[feature(no_coverage)]` to the function
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue