From 8e03371fc3209b8b91989b108314e35f471d6b89 Mon Sep 17 00:00:00 2001 From: Andy Caldwell Date: Wed, 9 Aug 2023 15:57:16 +0100 Subject: [PATCH] Rework no_coverage to coverage(off) --- .../src/deriving/cmp/eq.rs | 2 +- .../rustc_builtin_macros/src/test_harness.rs | 8 +-- .../src/coverageinfo/mapgen.rs | 4 +- compiler/rustc_codegen_ssa/messages.ftl | 2 + .../rustc_codegen_ssa/src/codegen_attrs.rs | 21 +++++- compiler/rustc_codegen_ssa/src/errors.rs | 7 ++ .../src/error_codes/E0788.md | 16 ++--- compiler/rustc_feature/src/active.rs | 6 +- compiler/rustc_feature/src/builtin_attrs.rs | 2 +- .../src/middle/codegen_fn_attrs.rs | 2 +- compiler/rustc_passes/messages.ftl | 26 +++---- compiler/rustc_passes/src/check_attr.rs | 22 +++--- compiler/rustc_passes/src/errors.rs | 16 ++--- compiler/rustc_span/src/symbol.rs | 3 +- library/core/src/cmp.rs | 7 +- library/core/src/lib.rs | 3 +- src/doc/rustc/src/instrument-coverage.md | 4 +- .../{no-coverage.md => coverage.md} | 8 +-- .../crates/hir-def/src/attr/builtin.rs | 2 +- .../crates/ide-db/src/generated/lints.rs | 10 +-- tests/pretty/tests-are-sorted.pp | 2 +- tests/ui/deriving/deriving-all-codegen.stdout | 28 ++++---- ...o_coverage.rs => feature-gate-coverage.rs} | 4 +- .../feature-gate-coverage.stderr | 12 ++++ .../feature-gate-no_coverage.stderr | 12 ---- tests/ui/lint/no-coverage.rs | 40 +++++------ tests/ui/lint/no-coverage.stderr | 72 +++++++++---------- 27 files changed, 183 insertions(+), 158 deletions(-) rename src/doc/unstable-book/src/language-features/{no-coverage.md => coverage.md} (80%) rename tests/ui/feature-gates/{feature-gate-no_coverage.rs => feature-gate-coverage.rs} (68%) create mode 100644 tests/ui/feature-gates/feature-gate-coverage.stderr delete mode 100644 tests/ui/feature-gates/feature-gate-no_coverage.stderr diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs index c78a0eb04a0..745358fde4b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs @@ -34,7 +34,7 @@ pub fn expand_deriving_eq( attributes: thin_vec![ cx.attr_word(sym::inline, span), cx.attr_nested_word(sym::doc, sym::hidden, span), - cx.attr_word(sym::no_coverage, span) + cx.attr_nested_word(sym::coverage, sym::off, span) ], fieldless_variants_strategy: FieldlessVariantsStrategy::Unify, combine_substructure: combine_substructure(Box::new(|a, b, c| { diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index d8846a9f0aa..ed0da7e115f 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -254,7 +254,7 @@ fn generate_test_harness( let expn_id = ext_cx.resolver.expansion_for_ast_pass( DUMMY_SP, AstPass::TestHarness, - &[sym::test, sym::rustc_attrs, sym::no_coverage], + &[sym::test, sym::rustc_attrs, sym::coverage], None, ); let def_site = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id()); @@ -335,8 +335,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { // #[rustc_main] let main_attr = ecx.attr_word(sym::rustc_main, sp); - // #[no_coverage] - let no_coverage_attr = ecx.attr_word(sym::no_coverage, sp); + // #[coverage(off)] + let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp); // pub fn main() { ... } let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new())); @@ -366,7 +366,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let main = P(ast::Item { ident: main_id, - attrs: thin_vec![main_attr, no_coverage_attr], + attrs: thin_vec![main_attr, coverage_attr], id: ast::DUMMY_NODE_ID, kind: main, vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None }, diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 97a99e51056..f0ed0a9d1b8 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -317,10 +317,10 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) { { let codegen_fn_attrs = tcx.codegen_fn_attrs(non_codegenned_def_id); - // If a function is marked `#[no_coverage]`, then skip generating a + // If a function is marked `#[coverage(off)]`, then skip generating a // dead code stub for it. if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_COVERAGE) { - debug!("skipping unused fn marked #[no_coverage]: {:?}", non_codegenned_def_id); + debug!("skipping unused fn marked #[coverage(off)]: {:?}", non_codegenned_def_id); continue; } diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 3dc83f50b21..9ce13ff469c 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -23,6 +23,8 @@ codegen_ssa_erroneous_constant = erroneous constant encountered codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error} +codegen_ssa_expected_coverage_symbol = expected `coverage(off)` or `coverage(on)` + codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)` codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index f6936c80b77..287f2292f4d 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -16,7 +16,10 @@ use rustc_target::spec::{abi, SanitizerSet}; use crate::errors; use crate::target_features::from_target_feature; -use crate::{errors::ExpectedUsedSymbol, target_features::check_target_feature_trait_unsafe}; +use crate::{ + errors::{ExpectedCoverageSymbol, ExpectedUsedSymbol}, + target_features::check_target_feature_trait_unsafe, +}; fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { use rustc_middle::mir::mono::Linkage::*; @@ -128,7 +131,21 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { .emit(); } } - sym::no_coverage => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE, + sym::coverage => { + let inner = attr.meta_item_list(); + match inner.as_deref() { + Some([item]) if item.has_name(sym::off) => { + codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE; + } + Some([item]) if item.has_name(sym::on) => { + // Allow #[coverage(on)] for being explicit, maybe also in future to enable + // coverage on a smaller scope within an excluded larger scopy. + } + Some(_) | None => { + tcx.sess.emit_err(ExpectedCoverageSymbol { span: attr.span }); + } + } + } sym::rustc_std_internal_symbol => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 41602321ded..fa49095c9e8 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -561,6 +561,13 @@ pub struct UnknownArchiveKind<'a> { pub kind: &'a str, } +#[derive(Diagnostic)] +#[diag(codegen_ssa_expected_coverage_symbol)] +pub struct ExpectedCoverageSymbol { + #[primary_span] + pub span: Span, +} + #[derive(Diagnostic)] #[diag(codegen_ssa_expected_used_symbol)] pub struct ExpectedUsedSymbol { diff --git a/compiler/rustc_error_codes/src/error_codes/E0788.md b/compiler/rustc_error_codes/src/error_codes/E0788.md index d26f9b59455..d655e51fa66 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0788.md +++ b/compiler/rustc_error_codes/src/error_codes/E0788.md @@ -1,4 +1,4 @@ -A `#[no_coverage]` attribute was applied to something which does not show up +A `#[coverage]` attribute was applied to something which does not show up in code coverage, or is too granular to be excluded from the coverage report. For now, this attribute can only be applied to function, method, and closure @@ -9,18 +9,18 @@ will just emit an `unused_attributes` lint instead of this error. Example of erroneous code: ```compile_fail,E0788 -#[no_coverage] +#[coverage(off)] struct Foo; -#[no_coverage] +#[coverage(on)] const FOO: Foo = Foo; ``` -`#[no_coverage]` tells the compiler to not generate coverage instrumentation for -a piece of code when the `-C instrument-coverage` flag is passed. Things like -structs and consts are not coverable code, and thus cannot do anything with this -attribute. +`#[coverage(off)]` tells the compiler to not generate coverage instrumentation +for a piece of code when the `-C instrument-coverage` flag is passed. Things +like structs and consts are not coverable code, and thus cannot do anything +with this attribute. If you wish to apply this attribute to all methods in an impl or module, manually annotate each method; it is not possible to annotate the entire impl -with a `#[no_coverage]` attribute. +with a `#[coverage]` attribute. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1941390dc4a..59a04114e86 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -398,6 +398,9 @@ declare_features! ( (active, const_trait_impl, "1.42.0", Some(67792), None), /// Allows the `?` operator in const contexts. (active, const_try, "1.56.0", Some(74935), None), + /// Allows function attribute `#[coverage(on/off)]`, to control coverage + /// instrumentation of that function. + (active, coverage, "1.53.0", Some(84605), None), /// Allows non-builtin attributes in inner attribute position. (active, custom_inner_attributes, "1.30.0", Some(54726), None), /// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`. @@ -509,9 +512,6 @@ declare_features! ( (active, never_type_fallback, "1.41.0", Some(65992), None), /// Allows `#![no_core]`. (active, no_core, "1.3.0", Some(29639), None), - /// Allows function attribute `#[no_coverage]`, to bypass coverage - /// instrumentation of that function. - (active, no_coverage, "1.53.0", Some(84605), None), /// Allows the use of `no_sanitize` attribute. (active, no_sanitize, "1.42.0", Some(39699), None), /// Allows using the `non_exhaustive_omitted_patterns` lint. diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index e745ef1ec07..49fd27de804 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -395,7 +395,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ template!(List: "address, kcfi, memory, thread"), DuplicatesOk, experimental!(no_sanitize) ), - gated!(no_coverage, Normal, template!(Word), WarnFollowing, experimental!(no_coverage)), + gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, experimental!(coverage)), ungated!( doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index 02fd6ed7ba6..4e5725876c4 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -87,7 +87,7 @@ bitflags! { /// #[cmse_nonsecure_entry]: with a TrustZone-M extension, declare a /// function as an entry function from Non-Secure code. const CMSE_NONSECURE_ENTRY = 1 << 14; - /// `#[no_coverage]`: indicates that the function should be ignored by + /// `#[coverage(off)]`: indicates that the function should be ignored by /// the MIR `InstrumentCoverage` pass and not added to the coverage map /// during codegen. const NO_COVERAGE = 1 << 15; diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 57598cf8bcf..bf8f1d3ddbd 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -113,6 +113,19 @@ passes_continue_labeled_block = .label = labeled blocks cannot be `continue`'d .block_label = labeled block the `continue` points to +passes_coverage_fn_defn = + `#[coverage]` may only be applied to function definitions + +passes_coverage_ignored_function_prototype = + `#[coverage]` is ignored on function prototypes + +passes_coverage_not_coverable = + `#[coverage]` must be applied to coverable code + .label = not coverable code + +passes_coverage_propagate = + `#[coverage]` does not propagate into items and must be applied to the contained functions directly + passes_dead_codes = { $multiple -> *[true] multiple {$descr}s are @@ -497,19 +510,6 @@ passes_naked_functions_operands = passes_naked_tracked_caller = cannot use `#[track_caller]` with `#[naked]` -passes_no_coverage_fn_defn = - `#[no_coverage]` may only be applied to function definitions - -passes_no_coverage_ignored_function_prototype = - `#[no_coverage]` is ignored on function prototypes - -passes_no_coverage_not_coverable = - `#[no_coverage]` must be applied to coverable code - .label = not coverable code - -passes_no_coverage_propagate = - `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly - passes_no_link = attribute should be applied to an `extern crate` item .label = not an `extern crate` item diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 50a087c7847..879d1dd680c 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -107,7 +107,7 @@ impl CheckAttrVisitor<'_> { match attr.name_or_empty() { sym::do_not_recommend => self.check_do_not_recommend(attr.span, target), sym::inline => self.check_inline(hir_id, attr, span, target), - sym::no_coverage => self.check_no_coverage(hir_id, attr, span, target), + sym::coverage => self.check_coverage(hir_id, attr, span, target), sym::non_exhaustive => self.check_non_exhaustive(hir_id, attr, span, target), sym::marker => self.check_marker(hir_id, attr, span, target), sym::target_feature => self.check_target_feature(hir_id, attr, span, target), @@ -327,16 +327,10 @@ impl CheckAttrVisitor<'_> { } } - /// Checks if a `#[no_coverage]` is applied directly to a function - fn check_no_coverage( - &self, - hir_id: HirId, - attr: &Attribute, - span: Span, - target: Target, - ) -> bool { + /// Checks if a `#[coverage]` is applied directly to a function + fn check_coverage(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool { match target { - // no_coverage on function is fine + // #[coverage] on function is fine Target::Fn | Target::Closure | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true, @@ -347,7 +341,7 @@ impl CheckAttrVisitor<'_> { UNUSED_ATTRIBUTES, hir_id, attr.span, - errors::IgnoredNoCoverageFnProto, + errors::IgnoredCoverageFnProto, ); true } @@ -357,7 +351,7 @@ impl CheckAttrVisitor<'_> { UNUSED_ATTRIBUTES, hir_id, attr.span, - errors::IgnoredNoCoveragePropagate, + errors::IgnoredCoveragePropagate, ); true } @@ -367,13 +361,13 @@ impl CheckAttrVisitor<'_> { UNUSED_ATTRIBUTES, hir_id, attr.span, - errors::IgnoredNoCoverageFnDefn, + errors::IgnoredCoverageFnDefn, ); true } _ => { - self.tcx.sess.emit_err(errors::IgnoredNoCoverageNotCoverable { + self.tcx.sess.emit_err(errors::IgnoredCoverageNotCoverable { attr_span: attr.span, defn_span: span, }); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 32dd02a4aa9..1b2a902114b 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -64,20 +64,20 @@ pub struct InlineNotFnOrClosure { } #[derive(LintDiagnostic)] -#[diag(passes_no_coverage_ignored_function_prototype)] -pub struct IgnoredNoCoverageFnProto; +#[diag(passes_coverage_ignored_function_prototype)] +pub struct IgnoredCoverageFnProto; #[derive(LintDiagnostic)] -#[diag(passes_no_coverage_propagate)] -pub struct IgnoredNoCoveragePropagate; +#[diag(passes_coverage_propagate)] +pub struct IgnoredCoveragePropagate; #[derive(LintDiagnostic)] -#[diag(passes_no_coverage_fn_defn)] -pub struct IgnoredNoCoverageFnDefn; +#[diag(passes_coverage_fn_defn)] +pub struct IgnoredCoverageFnDefn; #[derive(Diagnostic)] -#[diag(passes_no_coverage_not_coverable, code = "E0788")] -pub struct IgnoredNoCoverageNotCoverable { +#[diag(passes_coverage_not_coverable, code = "E0788")] +pub struct IgnoredCoverageNotCoverable { #[primary_span] pub attr_span: Span, #[label] diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 2bb58f94adc..2dfb2e5e29d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -573,6 +573,7 @@ symbols! { cosf32, cosf64, count, + coverage, cr, crate_id, crate_in_paths, @@ -1037,7 +1038,6 @@ symbols! { no, no_builtins, no_core, - no_coverage, no_crate_inject, no_debug, no_default_passes, @@ -1068,6 +1068,7 @@ symbols! { note, object_safe_for_dispatch, of, + off, offset, offset_of, omit_gdb_pretty_printer_section, diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 3c127efb390..be9f75deead 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -289,7 +289,8 @@ pub trait Eq: PartialEq { // // This should never be implemented by hand. #[doc(hidden)] - #[no_coverage] // rust-lang/rust#84605 + #[cfg_attr(bootstrap, no_coverage)] // rust-lang/rust#84605 + #[cfg_attr(not(bootstrap), coverage(off))] // #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn assert_receiver_is_total_eq(&self) {} @@ -298,7 +299,9 @@ pub trait Eq: PartialEq { /// Derive macro generating an impl of the trait [`Eq`]. #[rustc_builtin_macro] #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] -#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match, no_coverage)] +#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match)] +#[cfg_attr(bootstrap, allow_internal_unstable(no_coverage))] +#[cfg_attr(not(bootstrap), allow_internal_unstable(coverage))] pub macro Eq($item:item) { /* compiler built-in */ } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index c3edd3a9d7d..e049dcc6eba 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -110,6 +110,8 @@ // // Library features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(no_coverage))] // rust-lang/rust#84605 +#![cfg_attr(not(bootstrap), feature(coverage))] // rust-lang/rust#84605 #![feature(char_indices_offset)] #![feature(const_align_of_val)] #![feature(const_align_of_val_raw)] @@ -235,7 +237,6 @@ #![feature(negative_impls)] #![feature(never_type)] #![feature(no_core)] -#![feature(no_coverage)] // rust-lang/rust#84605 #![feature(platform_intrinsics)] #![feature(prelude_import)] #![feature(repr_simd)] diff --git a/src/doc/rustc/src/instrument-coverage.md b/src/doc/rustc/src/instrument-coverage.md index 2535cd4f12c..5b766318331 100644 --- a/src/doc/rustc/src/instrument-coverage.md +++ b/src/doc/rustc/src/instrument-coverage.md @@ -173,9 +173,9 @@ Some of the more notable options in this example include: [`llvm-cov report`]: https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-report [`llvm-cov show`]: https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-show -> **Note**: Coverage can also be disabled on an individual function by annotating the function with the [`no_coverage` attribute] (which requires the feature flag `#![feature(no_coverage)]`). +> **Note**: Coverage can also be disabled on an individual function by annotating the function with the [`coverage(off)` attribute] (which requires the feature flag `#![feature(coverage)]`). -[`no_coverage` attribute]: ../unstable-book/language-features/no-coverage.html +[`coverage` attribute]: ../unstable-book/language-features/coverage.html ## Interpreting reports diff --git a/src/doc/unstable-book/src/language-features/no-coverage.md b/src/doc/unstable-book/src/language-features/coverage.md similarity index 80% rename from src/doc/unstable-book/src/language-features/no-coverage.md rename to src/doc/unstable-book/src/language-features/coverage.md index 327cdb39791..d200bf6b2bc 100644 --- a/src/doc/unstable-book/src/language-features/no-coverage.md +++ b/src/doc/unstable-book/src/language-features/coverage.md @@ -1,4 +1,4 @@ -# `no_coverage` +# `coverage` The tracking issue for this feature is: [#84605] @@ -6,7 +6,7 @@ The tracking issue for this feature is: [#84605] --- -The `no_coverage` attribute can be used to selectively disable coverage +The `coverage` attribute can be used to selectively disable coverage instrumentation in an annotated function. This might be useful to: - Avoid instrumentation overhead in a performance critical function @@ -16,14 +16,14 @@ instrumentation in an annotated function. This might be useful to: ## Example ```rust -#![feature(no_coverage)] +#![feature(coverage)] // `foo()` will get coverage instrumentation (by default) fn foo() { // ... } -#[no_coverage] +#[coverage(off)] fn bar() { // ... } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs index cead64a3374..9bd0c30b105 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs @@ -239,7 +239,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[ template!(List: "address, kcfi, memory, thread"), DuplicatesOk, experimental!(no_sanitize) ), - gated!(no_coverage, Normal, template!(Word), WarnFollowing, experimental!(no_coverage)), + gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, experimental!(coverage)), ungated!( doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index 49b37024a5e..57563a17483 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -3505,8 +3505,8 @@ This serves two purposes: "##, }, Lint { - label: "no_coverage", - description: r##"# `no_coverage` + label: "coverage", + description: r##"# `coverage` The tracking issue for this feature is: [#84605] @@ -3514,7 +3514,7 @@ The tracking issue for this feature is: [#84605] --- -The `no_coverage` attribute can be used to selectively disable coverage +The `coverage` attribute can be used to selectively disable coverage instrumentation in an annotated function. This might be useful to: - Avoid instrumentation overhead in a performance critical function @@ -3524,14 +3524,14 @@ instrumentation in an annotated function. This might be useful to: ## Example ```rust -#![feature(no_coverage)] +#![feature(coverage)] // `foo()` will get coverage instrumentation (by default) fn foo() { // ... } -#[no_coverage] +#[coverage(off)] fn bar() { // ... } diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 7d7f682130d..fd9386be8f3 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -79,7 +79,7 @@ pub const a_test: test::TestDescAndFn = }; fn a_test() {} #[rustc_main] -#[no_coverage] +#[coverage(off)] pub fn main() -> () { extern crate test; test::test_main_static(&[&a_test, &m_test, &z_test]) diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index 6bfc859bfe8..3d9f8129d93 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -60,7 +60,7 @@ impl ::core::marker::StructuralEq for Empty { } impl ::core::cmp::Eq for Empty { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -135,7 +135,7 @@ impl ::core::marker::StructuralEq for Point { } impl ::core::cmp::Eq for Point { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; } @@ -221,7 +221,7 @@ impl ::core::marker::StructuralEq for PackedPoint { } impl ::core::cmp::Eq for PackedPoint { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; } @@ -334,7 +334,7 @@ impl ::core::marker::StructuralEq for Big { } impl ::core::cmp::Eq for Big { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; } @@ -500,7 +500,7 @@ impl ::core::marker::StructuralEq for Unsized { } impl ::core::cmp::Eq for Unsized { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq<[u32]>; } @@ -615,7 +615,7 @@ impl ::core::cmp::Eq for Generic where T::A: ::core::cmp::Eq { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; @@ -738,7 +738,7 @@ impl () { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; @@ -821,7 +821,7 @@ impl ::core::marker::StructuralEq for Enum0 { } impl ::core::cmp::Eq for Enum0 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -892,7 +892,7 @@ impl ::core::marker::StructuralEq for Enum1 { } impl ::core::cmp::Eq for Enum1 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; } @@ -959,7 +959,7 @@ impl ::core::marker::StructuralEq for Fieldless1 { } impl ::core::cmp::Eq for Fieldless1 { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -1034,7 +1034,7 @@ impl ::core::marker::StructuralEq for Fieldless { } impl ::core::cmp::Eq for Fieldless { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () {} } #[automatically_derived] @@ -1142,7 +1142,7 @@ impl ::core::marker::StructuralEq for Mixed { } impl ::core::cmp::Eq for Mixed { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq>; @@ -1270,7 +1270,7 @@ impl ::core::marker::StructuralEq for Fielded { } impl ::core::cmp::Eq for Fielded { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; @@ -1393,7 +1393,7 @@ impl ::core::cmp::Eq for EnumGeneric { #[inline] #[doc(hidden)] - #[no_coverage] + #[coverage(off)] fn assert_receiver_is_total_eq(&self) -> () { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; diff --git a/tests/ui/feature-gates/feature-gate-no_coverage.rs b/tests/ui/feature-gates/feature-gate-coverage.rs similarity index 68% rename from tests/ui/feature-gates/feature-gate-no_coverage.rs rename to tests/ui/feature-gates/feature-gate-coverage.rs index fd4c6f76059..75336d86c5d 100644 --- a/tests/ui/feature-gates/feature-gate-no_coverage.rs +++ b/tests/ui/feature-gates/feature-gate-coverage.rs @@ -1,12 +1,12 @@ #![crate_type = "lib"] -#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(no_coverage)` +#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(coverage)` struct Foo { a: u8, b: u32, } -#[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature +#[coverage(off)] //~ ERROR the `#[coverage]` attribute is an experimental feature fn requires_feature_no_coverage() -> bool { let bar = Foo { a: 0, b: 0 }; bar == Foo { a: 0, b: 0 } diff --git a/tests/ui/feature-gates/feature-gate-coverage.stderr b/tests/ui/feature-gates/feature-gate-coverage.stderr new file mode 100644 index 00000000000..4036c046c74 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-coverage.stderr @@ -0,0 +1,12 @@ +error[E0658]: the `#[coverage]` attribute is an experimental feature + --> $DIR/feature-gate-coverage.rs:9:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #84605 for more information + = help: add `#![feature(coverage)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-no_coverage.stderr b/tests/ui/feature-gates/feature-gate-no_coverage.stderr deleted file mode 100644 index f7167e0b771..00000000000 --- a/tests/ui/feature-gates/feature-gate-no_coverage.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: the `#[no_coverage]` attribute is an experimental feature - --> $DIR/feature-gate-no_coverage.rs:9:1 - | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ - | - = note: see issue #84605 for more information - = help: add `#![feature(no_coverage)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/lint/no-coverage.rs b/tests/ui/lint/no-coverage.rs index 07906a43472..92a5ecf51ad 100644 --- a/tests/ui/lint/no-coverage.rs +++ b/tests/ui/lint/no-coverage.rs @@ -1,55 +1,55 @@ #![feature(extern_types)] -#![feature(no_coverage)] +#![feature(coverage)] #![feature(impl_trait_in_assoc_type)] #![warn(unused_attributes)] -#![no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#![coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly -#[no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly trait Trait { - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code const X: u32; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T; type U; } -#[no_coverage] -//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] +//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly impl Trait for () { const X: u32 = 0; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T = Self; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type U = impl Trait; //~ ERROR unconstrained opaque type } extern "C" { - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code static X: u32; - #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code type T; } -#[no_coverage] +#[coverage(off)] fn main() { - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions let _ = (); match () { - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions () => (), } - #[no_coverage] - //~^ WARN `#[no_coverage]` may only be applied to function definitions + #[coverage(off)] + //~^ WARN `#[coverage]` may only be applied to function definitions return (); } diff --git a/tests/ui/lint/no-coverage.stderr b/tests/ui/lint/no-coverage.stderr index 404efbeac1e..a87b0fb49f0 100644 --- a/tests/ui/lint/no-coverage.stderr +++ b/tests/ui/lint/no-coverage.stderr @@ -1,8 +1,8 @@ -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:8:1 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/no-coverage.rs:4:9 @@ -10,83 +10,83 @@ note: the lint level is defined here LL | #![warn(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:20:1 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:42:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:47:9 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -warning: `#[no_coverage]` may only be applied to function definitions +warning: `#[coverage]` may only be applied to function definitions --> $DIR/no-coverage.rs:52:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:11:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | const X: u32; | ------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:14:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T; | ------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:25:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T = Self; | -------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:28:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type U = impl Trait; | -------------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:33:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | static X: u32; | -------------- not coverable code -error[E0788]: `#[no_coverage]` must be applied to coverable code +error[E0788]: `#[coverage]` must be applied to coverable code --> $DIR/no-coverage.rs:36:5 | -LL | #[no_coverage] - | ^^^^^^^^^^^^^^ +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ LL | type T; | ------- not coverable code -warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly +warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly --> $DIR/no-coverage.rs:5:1 | -LL | #![no_coverage] - | ^^^^^^^^^^^^^^^ +LL | #![coverage(off)] + | ^^^^^^^^^^^^^^^^^ error: unconstrained opaque type --> $DIR/no-coverage.rs:29:14