coverage: Rename CoverageStatus to CoverageAttrKind
This patch also prepares the affected code in `coverage_attr_on` for some subsequent changes.
This commit is contained in:
parent
2761034176
commit
b4d0c91635
3 changed files with 27 additions and 32 deletions
|
|
@ -110,18 +110,10 @@ pub enum DeprecatedSince {
|
|||
Err,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Encodable,
|
||||
Decodable,
|
||||
Clone,
|
||||
HashStable_Generic,
|
||||
PrintAttribute
|
||||
)]
|
||||
pub enum CoverageStatus {
|
||||
/// Successfully-parsed value of a `#[coverage(..)]` attribute.
|
||||
#[derive(Copy, Debug, Eq, PartialEq, Encodable, Decodable, Clone)]
|
||||
#[derive(HashStable_Generic, PrintAttribute)]
|
||||
pub enum CoverageAttrKind {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
|
@ -304,8 +296,8 @@ pub enum AttributeKind {
|
|||
/// Represents `#[const_trait]`.
|
||||
ConstTrait(Span),
|
||||
|
||||
/// Represents `#[coverage]`.
|
||||
Coverage(Span, CoverageStatus),
|
||||
/// Represents `#[coverage(..)]`.
|
||||
Coverage(Span, CoverageAttrKind),
|
||||
|
||||
///Represents `#[rustc_deny_explicit_impl]`.
|
||||
DenyExplicitImpl(Span),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, OptimizeAttr, UsedBy};
|
||||
use rustc_attr_data_structures::{AttributeKind, CoverageAttrKind, OptimizeAttr, UsedBy};
|
||||
use rustc_feature::{AttributeTemplate, template};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::{Span, Symbol, sym};
|
||||
|
|
@ -78,16 +78,16 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
|
|||
return None;
|
||||
};
|
||||
|
||||
let status = match arg.path().word_sym() {
|
||||
Some(sym::off) => CoverageStatus::Off,
|
||||
Some(sym::on) => CoverageStatus::On,
|
||||
let kind = match arg.path().word_sym() {
|
||||
Some(sym::off) => CoverageAttrKind::Off,
|
||||
Some(sym::on) => CoverageAttrKind::On,
|
||||
None | Some(_) => {
|
||||
fail_incorrect_argument(arg.span());
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(AttributeKind::Coverage(cx.attr_span, status))
|
||||
Some(AttributeKind::Coverage(cx.attr_span, kind))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, find_attr};
|
||||
use rustc_attr_data_structures::{AttributeKind, CoverageAttrKind, find_attr};
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::mir::coverage::{BasicCoverageBlock, CoverageIdsInfo, CoverageKind, MappingKind};
|
||||
|
|
@ -57,20 +57,23 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||
|
||||
/// Query implementation for `coverage_attr_on`.
|
||||
fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
// Check for annotations directly on this def.
|
||||
if let Some(coverage_status) =
|
||||
find_attr!(tcx.get_all_attrs(def_id), AttributeKind::Coverage(_, status) => status)
|
||||
// Check for a `#[coverage(..)]` attribute on this def.
|
||||
if let Some(kind) =
|
||||
find_attr!(tcx.get_all_attrs(def_id), AttributeKind::Coverage(_sp, kind) => kind)
|
||||
{
|
||||
*coverage_status == CoverageStatus::On
|
||||
} else {
|
||||
match tcx.opt_local_parent(def_id) {
|
||||
// Check the parent def (and so on recursively) until we find an
|
||||
// enclosing attribute or reach the crate root.
|
||||
Some(parent) => tcx.coverage_attr_on(parent),
|
||||
// We reached the crate root without seeing a coverage attribute, so
|
||||
// allow coverage instrumentation by default.
|
||||
None => true,
|
||||
match kind {
|
||||
CoverageAttrKind::On => return true,
|
||||
CoverageAttrKind::Off => return false,
|
||||
}
|
||||
};
|
||||
|
||||
// Check the parent def (and so on recursively) until we find an
|
||||
// enclosing attribute or reach the crate root.
|
||||
match tcx.opt_local_parent(def_id) {
|
||||
Some(parent) => tcx.coverage_attr_on(parent),
|
||||
// We reached the crate root without seeing a coverage attribute, so
|
||||
// allow coverage instrumentation by default.
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue