Skip to content

Commit

Permalink
Stabilize #[coverage] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Sep 24, 2024
1 parent 7042c26 commit 2a11c1d
Show file tree
Hide file tree
Showing 92 changed files with 84 additions and 223 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ declare_features! (
(accepted, const_refs_to_cell, "CURRENT_RUSTC_VERSION", Some(80384)),
/// Allows implementing `Copy` for closures where possible (RFC 2132).
(accepted, copy_closures, "1.26.0", Some(44490)),
/// Allows function attribute `#[coverage(on/off)]`, to control coverage
/// instrumentation of that function.
(accepted, coverage_attribute, "CURRENT_RUSTC_VERSION", Some(84605)),
/// Allows `crate` in paths.
(accepted, crate_in_paths, "1.30.0", Some(45477)),
/// Allows users to provide classes for fenced code block using `class:classname`.
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
EncodeCrossCrate::No, experimental!(no_sanitize)
),
gated!(
ungated!(
coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
ErrorPreceding, EncodeCrossCrate::No,
coverage_attribute, experimental!(coverage)
),

ungated!(
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,6 @@ declare_features! (
(unstable, coroutine_clone, "1.65.0", Some(95360)),
/// Allows defining coroutines.
(unstable, coroutines, "1.21.0", Some(43122)),
/// Allows function attribute `#[coverage(on/off)]`, to control coverage
/// instrumentation of that function.
(unstable, coverage_attribute, "1.74.0", Some(84605)),
/// Allows non-builtin attributes in inner attribute position.
(unstable, custom_inner_attributes, "1.30.0", Some(54726)),
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub trait Eq: PartialEq<Self> {
#[rustc_builtin_macro]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match)]
#[allow_internal_unstable(coverage_attribute)]
#[cfg_attr(bootstrap, allow_internal_unstable(coverage_attribute))]
pub macro Eq($item:item) {
/* compiler built-in */
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
//
// Library features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(coverage_attribute))]
#![feature(array_ptr_get)]
#![feature(asm_experimental_arch)]
#![feature(const_align_of_val)]
Expand Down Expand Up @@ -161,7 +162,6 @@
#![feature(const_ub_checks)]
#![feature(const_unicode_case_lookup)]
#![feature(const_unsafecell_get_mut)]
#![feature(coverage_attribute)]
#![feature(do_not_recommend)]
#![feature(duration_consts_float)]
#![feature(f128_const)]
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,8 @@ pub(crate) mod builtin {
///
/// [the reference]: ../../../reference/attributes/testing.html#the-test-attribute
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
#[allow_internal_unstable(test, rustc_attrs)]
#[cfg_attr(bootstrap, allow_internal_unstable(coverage_attribute))]
#[rustc_builtin_macro]
pub macro test($item:item) {
/* compiler built-in */
Expand All @@ -1667,7 +1668,8 @@ pub(crate) mod builtin {
soft,
reason = "`bench` is a part of custom test frameworks which are unstable"
)]
#[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
#[allow_internal_unstable(test, rustc_attrs)]
#[cfg_attr(bootstrap, allow_internal_unstable(coverage_attribute))]
#[rustc_builtin_macro]
pub macro bench($item:item) {
/* compiler built-in */
Expand Down
30 changes: 0 additions & 30 deletions src/doc/unstable-book/src/language-features/coverage-attribute.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
experimental!(no_sanitize)
),
gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, coverage_attribute, experimental!(coverage)),
ungated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing),

ungated!(
doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
LL| |#![feature(noop_waker)]
LL| |#![allow(unused_assignments, dead_code)]
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
#![feature(noop_waker)]
#![allow(unused_assignments, dead_code)]
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async2.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |//@ edition: 2018
LL| |
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
#![feature(noop_waker)]
//@ edition: 2018

Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async_block.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |//@ edition: 2021
LL| |
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/async_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
#![feature(noop_waker)]
//@ edition: 2021

Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/impl.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |// Checks that `#[coverage(..)]` can be applied to impl and impl-trait blocks,
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Checks that `#[coverage(..)]` can be applied to impl and impl-trait blocks,
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/module.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |// Checks that `#[coverage(..)]` can be applied to modules, and is inherited
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Checks that `#[coverage(..)]` can be applied to modules, and is inherited
Expand Down
3 changes: 1 addition & 2 deletions tests/coverage/attr/nested.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
LL| |#![feature(stmt_expr_attributes)]
LL| |//@ edition: 2021
LL| |
LL| |// Demonstrates the interaction between #[coverage(off)] and various kinds of
Expand Down Expand Up @@ -103,4 +103,3 @@
LL| | closure_expr();
LL| | closure_tail();
LL| |}

2 changes: 1 addition & 1 deletion tests/coverage/attr/nested.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(coverage_attribute, stmt_expr_attributes)]
#![feature(stmt_expr_attributes)]
//@ edition: 2021

// Demonstrates the interaction between #[coverage(off)] and various kinds of
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/off-on-sandwich.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |// Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]`
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/attr/off-on-sandwich.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Demonstrates the interaction of `#[coverage(off)]` and `#[coverage(on)]`
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/auxiliary/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(coverage_attribute, noop_waker)]
#![feature(noop_waker)]
//@ edition: 2021

use core::future::Future;
Expand Down
2 changes: 0 additions & 2 deletions tests/coverage/await_ready.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |#![coverage(off)]
LL| |//@ edition: 2021
Expand All @@ -22,4 +21,3 @@
LL| | let mut future = Box::pin(await_ready());
LL| | executor::block_on(future.as_mut());
LL| |}

1 change: 0 additions & 1 deletion tests/coverage/await_ready.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
#![feature(noop_waker)]
#![coverage(off)]
//@ edition: 2021
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/bad_counter_ids.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Copt-level=0 -Zmir-opt-level=3
LL| |
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/bad_counter_ids.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Copt-level=0 -Zmir-opt-level=3

Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/generics.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/generics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/guard.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/guard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
3 changes: 1 addition & 2 deletions tests/coverage/branch/if-let.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LL| |#![feature(coverage_attribute, let_chains)]
LL| |#![feature(let_chains)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down Expand Up @@ -68,4 +68,3 @@
LL| |}
LL| |
LL| |// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.

2 changes: 1 addition & 1 deletion tests/coverage/branch/if-let.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(coverage_attribute, let_chains)]
#![feature(let_chains)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/if.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/if.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/lazy-boolean.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/lazy-boolean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/let-else.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/let-else.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/match-arms.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/match-arms.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/match-trivial.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/match-trivial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/no-mir-spans.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch,no-mir-spans
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/no-mir-spans.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch,no-mir-spans
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/while.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/branch/while.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/closure_macro_async.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |//@ edition: 2018
LL| |
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/closure_macro_async.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
#![feature(noop_waker)]
//@ edition: 2018

Expand Down
1 change: 0 additions & 1 deletion tests/coverage/closure_unit_return.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |// Regression test for an inconsistency between functions that return the value
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/closure_unit_return.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Regression test for an inconsistency between functions that return the value
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/condition/conditions.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ compile-flags: -Zcoverage-options=condition
LL| |//@ llvm-cov-flags: --show-branches=count
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/condition/conditions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Zcoverage-options=condition
//@ llvm-cov-flags: --show-branches=count
Expand Down
3 changes: 1 addition & 2 deletions tests/coverage/coverage_attr_closure.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LL| |#![feature(coverage_attribute, stmt_expr_attributes)]
LL| |#![feature(stmt_expr_attributes)]
LL| |#![allow(dead_code)]
LL| |//@ edition: 2021
LL| |
Expand Down Expand Up @@ -40,4 +40,3 @@
LL| | contains_closures_on();
LL| | contains_closures_off();
LL| |}

2 changes: 1 addition & 1 deletion tests/coverage/coverage_attr_closure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(coverage_attribute, stmt_expr_attributes)]
#![feature(stmt_expr_attributes)]
#![allow(dead_code)]
//@ edition: 2021

Expand Down
1 change: 0 additions & 1 deletion tests/coverage/fn_sig_into_try.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |// Regression test for inconsistent handling of function signature spans that
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/fn_sig_into_try.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Regression test for inconsistent handling of function signature spans that
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/if_not.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |#[rustfmt::skip]
Expand Down
1 change: 0 additions & 1 deletion tests/coverage/if_not.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(coverage_attribute)]
//@ edition: 2021

#[rustfmt::skip]
Expand Down
Loading

0 comments on commit 2a11c1d

Please sign in to comment.