-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Adds feature-gated #[no_coverage]
function attribute, to fix derived Eq 0
coverage issue #83601
#84562
Conversation
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: rust-lang#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 rust-lang#84561, and added a coverage test to demonstrate this issue.
@nikomatsakis - Does this implementation work for you? Is there anything else needed before this can be approved and merged (now that feature gating is supported)? |
#[no_coverage]
option for functions, to fix derived Eq 0
coverage issue #83601
#[no_coverage]
option for functions, to fix derived Eq 0
coverage issue #83601#[no_coverage]
function attribute, to fix derived Eq 0
coverage issue #83601
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should go ahead and add this attribute to all the builtin derives (in either this change or a future one). I don't see much point in making sure they have coverage; they're already well tested in the compiler.
if list.iter().any(|nested_meta_item| nested_meta_item.has_name(sym::no_coverage)) { | ||
tcx.sess.mark_attr_used(attr); | ||
no_coverage_feature_enabled = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't AssumeUsed make this unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it appears to be necessary. I tried removing it, and when compiling rustc I now get the error:
error: unused attribute
--> library/core/src/cmp.rs:277:32
|
277 | #[cfg_attr(not(bootstrap), feature(no_coverage))]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D unused-attributes` implied by `-D warnings`
Looks great modulo comments. |
✌️ @richkadel can now approve this pull request |
I also like the idea of combining the first two comments on #84605 by making it The particulars of which things to make covered by default are a little hazy to me at this point, though. Really the problem I want to fix is that assert messages in tests appear uncovered, but that's kind of the point :) |
Hmm... Maybe I could be convinced, but I think we should discuss this, and for now I think it should be left out of this PR. The function with But I think it's worth discussing, but skipping coverage reporting that can provide valid feedback to the user, for builtin traits, feels like a judgement call we would be making. |
Yes, I saw the comments, and I do want to consider them. Since this is feature-gated (and fixes a bug), I'd like to land this with I did consider something like In fact, I think coverage is especially relevant to tests, so I wouldn't want to disable it for tests by default, or require the user add the attribute in order to get test coverage. The only other coverage-related attribute we may want to consider, in the future, is an attribute to enable coverage of unwind paths (#78544). But the MIR It's definitely not uncommon for attributes to start with |
@bors r=tmandry |
📌 Commit 3a5df48 has been approved by |
Agreed that coverage is relevant to tests, but I don't know if it's very relevant to the test functions themselves. But like I said, there might be a different way of getting at the problem I'm talking about. In fact, your reply made me think of an approach I like better, which is removing counters that are along a path that always panics. We don't instrument the full panic paths anyway, and this is a straightforward analysis to do. None of this is very relevant to this PR though! I just wanted to put my ideas down somewhere.. |
☀️ Test successful - checks-actions |
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 markfunctions that should be ignored by
InstrumentCoverage
and thecoverage
mapgen
(during codegen).Adding a
no_coverage
feature gate with tracking issue #84605.r? @tmandry
cc: @wesleywiser