diff options
| author | Rich Kadel <richkadel@google.com> | 2021-04-25 13:34:03 -0700 |
|---|---|---|
| committer | Rich Kadel <richkadel@google.com> | 2021-04-27 11:11:56 -0700 |
| commit | 888d0b4c9691ffcba7cb326a1cd1fc73feb38f57 (patch) | |
| tree | f9fd7d1e8afa1f610aab6081b1bf06a1de3edf75 /src | |
| parent | 1919b3f22706fee0b2c6ac3d42316545900b7734 (diff) | |
| download | rust-888d0b4c9691ffcba7cb326a1cd1fc73feb38f57.tar.gz rust-888d0b4c9691ffcba7cb326a1cd1fc73feb38f57.zip | |
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). While testing, I also noticed two other issues: * spanview debug file output ICEd on a function with no body. The workaround for this is included in this PR. * `assert_*!()` macro coverage can appear covered if followed by another `assert_*!()` macro. Normally they appear uncovered. I submitted a new Issue #84561, and added a coverage test to demonstrate this issue.
Diffstat (limited to 'src')
5 files changed, 97 insertions, 1 deletions
diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-83601.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-83601.txt new file mode 100644 index 00000000000..46f3add9427 --- /dev/null +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-83601.txt @@ -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|} + diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt new file mode 100644 index 00000000000..faafa828817 --- /dev/null +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt @@ -0,0 +1,34 @@ + 1| |// FIXME(#84561): function-like macros produce unintuitive coverage results. + 2| |// This test demonstrates some of the problems. + 3| | + 4| 9|#[derive(Debug, PartialEq, Eq)] + ^5 + ------------------ + | <issue_84561::Foo as core::cmp::PartialEq>::eq: + | 4| 9|#[derive(Debug, PartialEq, Eq)] + ------------------ + | Unexecuted instantiation: <issue_84561::Foo as core::cmp::PartialEq>::ne + ------------------ + 5| |struct Foo(u32); + 6| | + 7| 1|fn main() { + 8| 1| let bar = Foo(1); + 9| 0| assert_eq!(bar, Foo(1)); + 10| 1| let baz = Foo(0); + 11| 0| assert_ne!(baz, Foo(1)); + 12| 1| println!("{:?}", Foo(1)); + 13| 1| println!("{:?}", bar); + 14| 1| println!("{:?}", baz); + 15| | + 16| 1| assert_eq!(Foo(1), Foo(1)); + 17| 1| assert_ne!(Foo(0), Foo(1)); + 18| 0| assert_eq!(Foo(2), Foo(2)); + 19| 1| let bar = Foo(1); + 20| 1| assert_ne!(Foo(0), Foo(3)); + 21| 1| assert_ne!(Foo(0), Foo(4)); + 22| 1| assert_eq!(Foo(3), Foo(3)); + 23| 0| assert_ne!(Foo(0), Foo(5)); + 24| 1| println!("{:?}", bar); + 25| 1| println!("{:?}", Foo(1)); + 26| 1|} + diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.partial_eq.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.partial_eq.txt index 4e4dde46b34..fc266653349 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.partial_eq.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.partial_eq.txt @@ -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 ------------------ diff --git a/src/test/run-make-fulldeps/coverage/issue-83601.rs b/src/test/run-make-fulldeps/coverage/issue-83601.rs new file mode 100644 index 00000000000..0b72a81947c --- /dev/null +++ b/src/test/run-make-fulldeps/coverage/issue-83601.rs @@ -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); +} diff --git a/src/test/run-make-fulldeps/coverage/issue-84561.rs b/src/test/run-make-fulldeps/coverage/issue-84561.rs new file mode 100644 index 00000000000..dc183685e3d --- /dev/null +++ b/src/test/run-make-fulldeps/coverage/issue-84561.rs @@ -0,0 +1,26 @@ +// FIXME(#84561): function-like macros produce unintuitive coverage results. +// This test demonstrates some of the problems. + +#[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); + + assert_eq!(Foo(1), Foo(1)); + assert_ne!(Foo(0), Foo(1)); + assert_eq!(Foo(2), Foo(2)); + let bar = Foo(1); + assert_ne!(Foo(0), Foo(3)); + assert_ne!(Foo(0), Foo(4)); + assert_eq!(Foo(3), Foo(3)); + assert_ne!(Foo(0), Foo(5)); + println!("{:?}", bar); + println!("{:?}", Foo(1)); +} |
