Skip to content

Commit b4d0c91

Browse files
committed
coverage: Rename CoverageStatus to CoverageAttrKind
This patch also prepares the affected code in `coverage_attr_on` for some subsequent changes.
1 parent 2761034 commit b4d0c91

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,10 @@ pub enum DeprecatedSince {
110110
Err,
111111
}
112112

113-
#[derive(
114-
Copy,
115-
Debug,
116-
Eq,
117-
PartialEq,
118-
Encodable,
119-
Decodable,
120-
Clone,
121-
HashStable_Generic,
122-
PrintAttribute
123-
)]
124-
pub enum CoverageStatus {
113+
/// Successfully-parsed value of a `#[coverage(..)]` attribute.
114+
#[derive(Copy, Debug, Eq, PartialEq, Encodable, Decodable, Clone)]
115+
#[derive(HashStable_Generic, PrintAttribute)]
116+
pub enum CoverageAttrKind {
125117
On,
126118
Off,
127119
}
@@ -304,8 +296,8 @@ pub enum AttributeKind {
304296
/// Represents `#[const_trait]`.
305297
ConstTrait(Span),
306298

307-
/// Represents `#[coverage]`.
308-
Coverage(Span, CoverageStatus),
299+
/// Represents `#[coverage(..)]`.
300+
Coverage(Span, CoverageAttrKind),
309301

310302
///Represents `#[rustc_deny_explicit_impl]`.
311303
DenyExplicitImpl(Span),

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, OptimizeAttr, UsedBy};
1+
use rustc_attr_data_structures::{AttributeKind, CoverageAttrKind, OptimizeAttr, UsedBy};
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_session::parse::feature_err;
44
use rustc_span::{Span, Symbol, sym};
@@ -78,16 +78,16 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
7878
return None;
7979
};
8080

81-
let status = match arg.path().word_sym() {
82-
Some(sym::off) => CoverageStatus::Off,
83-
Some(sym::on) => CoverageStatus::On,
81+
let kind = match arg.path().word_sym() {
82+
Some(sym::off) => CoverageAttrKind::Off,
83+
Some(sym::on) => CoverageAttrKind::On,
8484
None | Some(_) => {
8585
fail_incorrect_argument(arg.span());
8686
return None;
8787
}
8888
};
8989

90-
Some(AttributeKind::Coverage(cx.attr_span, status))
90+
Some(AttributeKind::Coverage(cx.attr_span, kind))
9191
}
9292
}
9393

compiler/rustc_mir_transform/src/coverage/query.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, find_attr};
1+
use rustc_attr_data_structures::{AttributeKind, CoverageAttrKind, find_attr};
22
use rustc_index::bit_set::DenseBitSet;
33
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
44
use rustc_middle::mir::coverage::{BasicCoverageBlock, CoverageIdsInfo, CoverageKind, MappingKind};
@@ -57,20 +57,23 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5757

5858
/// Query implementation for `coverage_attr_on`.
5959
fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
60-
// Check for annotations directly on this def.
61-
if let Some(coverage_status) =
62-
find_attr!(tcx.get_all_attrs(def_id), AttributeKind::Coverage(_, status) => status)
60+
// Check for a `#[coverage(..)]` attribute on this def.
61+
if let Some(kind) =
62+
find_attr!(tcx.get_all_attrs(def_id), AttributeKind::Coverage(_sp, kind) => kind)
6363
{
64-
*coverage_status == CoverageStatus::On
65-
} else {
66-
match tcx.opt_local_parent(def_id) {
67-
// Check the parent def (and so on recursively) until we find an
68-
// enclosing attribute or reach the crate root.
69-
Some(parent) => tcx.coverage_attr_on(parent),
70-
// We reached the crate root without seeing a coverage attribute, so
71-
// allow coverage instrumentation by default.
72-
None => true,
64+
match kind {
65+
CoverageAttrKind::On => return true,
66+
CoverageAttrKind::Off => return false,
7367
}
68+
};
69+
70+
// Check the parent def (and so on recursively) until we find an
71+
// enclosing attribute or reach the crate root.
72+
match tcx.opt_local_parent(def_id) {
73+
Some(parent) => tcx.coverage_attr_on(parent),
74+
// We reached the crate root without seeing a coverage attribute, so
75+
// allow coverage instrumentation by default.
76+
None => true,
7477
}
7578
}
7679

0 commit comments

Comments
 (0)