|
| 1 | +use rustc_attr_data_structures::{AttributeKind, CoverageStatus, find_attr}; |
1 | 2 | use rustc_index::bit_set::DenseBitSet; |
2 | 3 | use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; |
3 | 4 | use rustc_middle::mir::coverage::{BasicCoverageBlock, CoverageIdsInfo, CoverageKind, MappingKind}; |
4 | 5 | use rustc_middle::mir::{Body, Statement, StatementKind}; |
5 | 6 | use rustc_middle::ty::{self, TyCtxt}; |
6 | 7 | use rustc_middle::util::Providers; |
7 | 8 | use rustc_span::def_id::LocalDefId; |
8 | | -use rustc_span::sym; |
9 | 9 | use tracing::trace; |
10 | 10 |
|
11 | 11 | use crate::coverage::counters::node_flow::make_node_counters; |
@@ -58,26 +58,20 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { |
58 | 58 | /// Query implementation for `coverage_attr_on`. |
59 | 59 | fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { |
60 | 60 | // Check for annotations directly on this def. |
61 | | - if let Some(attr) = tcx.get_attr(def_id, sym::coverage) { |
62 | | - match attr.meta_item_list().as_deref() { |
63 | | - Some([item]) if item.has_name(sym::off) => return false, |
64 | | - Some([item]) if item.has_name(sym::on) => return true, |
65 | | - Some(_) | None => { |
66 | | - // Other possibilities should have been rejected by `rustc_parse::validate_attr`. |
67 | | - // Use `span_delayed_bug` to avoid an ICE in failing builds (#127880). |
68 | | - tcx.dcx().span_delayed_bug(attr.span(), "unexpected value of coverage attribute"); |
69 | | - } |
| 61 | + if let Some(coverage_status) = |
| 62 | + find_attr!(tcx.get_all_attrs(def_id), AttributeKind::Coverage(_, status) => status) |
| 63 | + { |
| 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, |
70 | 73 | } |
71 | 74 | } |
72 | | - |
73 | | - match tcx.opt_local_parent(def_id) { |
74 | | - // Check the parent def (and so on recursively) until we find an |
75 | | - // enclosing attribute or reach the crate root. |
76 | | - Some(parent) => tcx.coverage_attr_on(parent), |
77 | | - // We reached the crate root without seeing a coverage attribute, so |
78 | | - // allow coverage instrumentation by default. |
79 | | - None => true, |
80 | | - } |
81 | 75 | } |
82 | 76 |
|
83 | 77 | /// Query implementation for `coverage_ids_info`. |
|
0 commit comments