Skip to content

Commit aaf2389

Browse files
authored
Rollup merge of #84871 - richkadel:no-coverage-unstable-only, r=nagisa
Disallows `#![feature(no_coverage)]` on stable and beta (using standard crate-level gating) Fixes: #84836 Removes the function-level feature gating solution originally implemented, and solves the same problem using `allow_internal_unstable`, so normal crate-level feature gating mechanism can still be used (which disallows the feature on stable and beta). I tested this, building the compiler with and without `CFG_DISABLE_UNSTABLE_FEATURES=1` With unstable features disabled, I get the expected result as shown here: ```shell $ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/run-make-fulldeps/coverage/no_cov_crate.rs error[E0554]: `#![feature]` may not be used on the dev release channel --> src/test/run-make-fulldeps/coverage/no_cov_crate.rs:2:1 | 2 | #![feature(no_coverage)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0554`. ``` r? ````@Mark-Simulacrum```` cc: ````@tmandry```` ````@wesleywiser````
2 parents 7835c78 + 3584c1d commit aaf2389

File tree

9 files changed

+18
-91
lines changed

9 files changed

+18
-91
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@ pub fn expand_deriving_eq(
1515
item: &Annotatable,
1616
push: &mut dyn FnMut(Annotatable),
1717
) {
18+
let span = cx.with_def_site_ctxt(span);
1819
let inline = cx.meta_word(span, sym::inline);
19-
let no_coverage_ident =
20-
rustc_ast::attr::mk_nested_word_item(Ident::new(sym::no_coverage, span));
21-
let no_coverage_feature =
22-
rustc_ast::attr::mk_list_item(Ident::new(sym::feature, span), vec![no_coverage_ident]);
23-
let no_coverage = cx.meta_word(span, sym::no_coverage);
2420
let hidden = rustc_ast::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
2521
let doc = rustc_ast::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
26-
let attrs = vec![
27-
cx.attribute(inline),
28-
cx.attribute(no_coverage_feature),
29-
cx.attribute(no_coverage),
30-
cx.attribute(doc),
31-
];
22+
let no_coverage = cx.meta_word(span, sym::no_coverage);
23+
let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)];
3224
let trait_def = TraitDef {
3325
span,
3426
attributes: Vec::new(),

compiler/rustc_feature/src/builtin_attrs.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
273273
template!(List: "address, memory, thread"),
274274
experimental!(no_sanitize)
275275
),
276-
ungated!(
277-
// Not exclusively gated at the crate level (though crate-level is
278-
// supported). The feature can alternatively be enabled on individual
279-
// functions.
280-
no_coverage, AssumedUsed,
281-
template!(Word),
282-
),
276+
gated!(no_coverage, AssumedUsed, template!(Word), experimental!(no_coverage)),
283277

284278
// FIXME: #14408 assume docs are used since rustdoc looks at them.
285279
ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")),

compiler/rustc_typeck/src/collect.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
26612661
let mut inline_span = None;
26622662
let mut link_ordinal_span = None;
26632663
let mut no_sanitize_span = None;
2664-
let mut no_coverage_feature_enabled = false;
2665-
let mut no_coverage_attr = None;
26662664
for attr in attrs.iter() {
26672665
if tcx.sess.check_name(attr, sym::cold) {
26682666
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
@@ -2726,15 +2724,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27262724
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED;
27272725
} else if tcx.sess.check_name(attr, sym::no_mangle) {
27282726
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
2729-
} else if attr.has_name(sym::feature) {
2730-
if let Some(list) = attr.meta_item_list() {
2731-
if list.iter().any(|nested_meta_item| nested_meta_item.has_name(sym::no_coverage)) {
2732-
tcx.sess.mark_attr_used(attr);
2733-
no_coverage_feature_enabled = true;
2734-
}
2735-
}
27362727
} else if tcx.sess.check_name(attr, sym::no_coverage) {
2737-
no_coverage_attr = Some(attr);
2728+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
27382729
} else if tcx.sess.check_name(attr, sym::rustc_std_internal_symbol) {
27392730
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
27402731
} else if tcx.sess.check_name(attr, sym::used) {
@@ -2945,23 +2936,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29452936
}
29462937
}
29472938

2948-
if let Some(no_coverage_attr) = no_coverage_attr {
2949-
if tcx.sess.features_untracked().no_coverage || no_coverage_feature_enabled {
2950-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE
2951-
} else {
2952-
let mut err = feature_err(
2953-
&tcx.sess.parse_sess,
2954-
sym::no_coverage,
2955-
no_coverage_attr.span,
2956-
"the `#[no_coverage]` attribute is an experimental feature",
2957-
);
2958-
if tcx.sess.parse_sess.unstable_features.is_nightly_build() {
2959-
err.help("or, alternatively, add `#[feature(no_coverage)]` to the function");
2960-
}
2961-
err.emit();
2962-
}
2963-
}
2964-
29652939
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
29662940
if !attr.has_name(sym::inline) {
29672941
return ia;

library/core/src/cmp.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ pub trait Eq: PartialEq<Self> {
274274
//
275275
// This should never be implemented by hand.
276276
#[doc(hidden)]
277-
#[cfg_attr(not(bootstrap), feature(no_coverage))]
278-
#[cfg_attr(not(bootstrap), no_coverage)]
277+
#[cfg_attr(not(bootstrap), no_coverage)] // rust-lang/rust#84605
279278
#[inline]
280279
#[stable(feature = "rust1", since = "1.0.0")]
281280
fn assert_receiver_is_total_eq(&self) {}
@@ -284,7 +283,7 @@ pub trait Eq: PartialEq<Self> {
284283
/// Derive macro generating an impl of the trait `Eq`.
285284
#[rustc_builtin_macro]
286285
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
287-
#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match)]
286+
#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match, no_coverage)]
288287
pub macro Eq($item:item) {
289288
/* compiler built-in */
290289
}

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
#![feature(const_caller_location)]
167167
#![feature(slice_ptr_get)]
168168
#![feature(no_niche)] // rust-lang/rust#68303
169+
#![cfg_attr(not(bootstrap), feature(no_coverage))] // rust-lang/rust#84605
169170
#![feature(int_error_matching)]
170171
#![deny(unsafe_op_in_unsafe_fn)]
171172

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.no_cov_func.txt

-19
This file was deleted.

src/test/run-make-fulldeps/coverage/no_cov_func.rs

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#![crate_type = "lib"]
22

3-
#[no_coverage]
4-
#[feature(no_coverage)] // does not have to be enabled before `#[no_coverage]`
5-
fn no_coverage_is_enabled_on_this_function() {}
3+
#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(no_coverage)`
4+
struct Foo {
5+
a: u8,
6+
b: u32,
7+
}
68

79
#[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature
8-
fn requires_feature_no_coverage() {}
10+
fn requires_feature_no_coverage() -> bool {
11+
let bar = Foo { a: 0, b: 0 };
12+
bar == Foo { a: 0, b: 0 }
13+
}

src/test/ui/feature-gates/feature-gate-no_coverage.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
error[E0658]: the `#[no_coverage]` attribute is an experimental feature
2-
--> $DIR/feature-gate-no_coverage.rs:7:1
2+
--> $DIR/feature-gate-no_coverage.rs:9:1
33
|
44
LL | #[no_coverage]
55
| ^^^^^^^^^^^^^^
66
|
77
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
88
= help: add `#![feature(no_coverage)]` to the crate attributes to enable
9-
= help: or, alternatively, add `#[feature(no_coverage)]` to the function
109

1110
error: aborting due to previous error
1211

0 commit comments

Comments
 (0)