-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Adds feature-gated #[no_coverage]
function attribute, to fix derived Eq 0
coverage issue #83601
#84562
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
Merged
Merged
Adds feature-gated #[no_coverage]
function attribute, to fix derived Eq 0
coverage issue #83601
#84562
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -781,6 +781,7 @@ symbols! { | |
no, | ||
no_builtins, | ||
no_core, | ||
no_coverage, | ||
no_crate_inject, | ||
no_debug, | ||
no_default_passes, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2661,6 +2661,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { | |
let mut inline_span = None; | ||
let mut link_ordinal_span = None; | ||
let mut no_sanitize_span = None; | ||
let mut no_coverage_feature_enabled = false; | ||
let mut no_coverage_attr = None; | ||
for attr in attrs.iter() { | ||
if tcx.sess.check_name(attr, sym::cold) { | ||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD; | ||
|
@@ -2724,6 +2726,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { | |
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED; | ||
} else if tcx.sess.check_name(attr, sym::no_mangle) { | ||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; | ||
} else if attr.has_name(sym::feature) { | ||
if let Some(list) = attr.meta_item_list() { | ||
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; | ||
} | ||
Comment on lines
+2731
to
+2734
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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:
|
||
} | ||
} else if tcx.sess.check_name(attr, sym::no_coverage) { | ||
no_coverage_attr = Some(attr); | ||
} else if tcx.sess.check_name(attr, sym::rustc_std_internal_symbol) { | ||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL; | ||
} else if tcx.sess.check_name(attr, sym::used) { | ||
|
@@ -2934,6 +2945,23 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { | |
} | ||
} | ||
|
||
if let Some(no_coverage_attr) = no_coverage_attr { | ||
if tcx.sess.features_untracked().no_coverage || no_coverage_feature_enabled { | ||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE | ||
} else { | ||
let mut err = feature_err( | ||
&tcx.sess.parse_sess, | ||
sym::no_coverage, | ||
no_coverage_attr.span, | ||
"the `#[no_coverage]` attribute is an experimental feature", | ||
); | ||
if tcx.sess.parse_sess.unstable_features.is_nightly_build() { | ||
err.help("or, alternatively, add `#[feature(no_coverage)]` to the function"); | ||
} | ||
err.emit(); | ||
} | ||
} | ||
|
||
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| { | ||
if !attr.has_name(sym::inline) { | ||
return ia; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-83601.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|} | ||
|
18 changes: 18 additions & 0 deletions
18
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_crate.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|} | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.