Skip to content

Commit 48448de

Browse files
committed
coverage: Get hole spans from nested items without fully visiting them
It turns out that this visitor doesn't actually need a custom `NestedFilter`; it just needs to override `visit_nested_item` and look up the item's span.
1 parent f39ca4b commit 48448de

File tree

1 file changed

+5
-14
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+5
-14
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod unexpand;
1010

1111
use rustc_hir as hir;
1212
use rustc_hir::intravisit::{Visitor, walk_expr};
13-
use rustc_middle::hir::nested_filter;
1413
use rustc_middle::mir::coverage::{
1514
CoverageKind, DecisionInfo, FunctionCoverageInfo, Mapping, MappingKind,
1615
};
@@ -352,19 +351,11 @@ fn extract_hole_spans_from_hir<'tcx>(
352351
}
353352

354353
impl<'hir, F: FnMut(Span)> Visitor<'hir> for HolesVisitor<'hir, F> {
355-
/// - We need `NestedFilter::INTRA = true` so that `visit_item` will be called.
356-
/// - Bodies of nested items don't actually get visited, because of the
357-
/// `visit_item` override.
358-
/// - For nested bodies that are not part of an item, we do want to visit any
359-
/// items contained within them.
360-
type NestedFilter = nested_filter::All;
361-
362-
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
363-
self.tcx
364-
}
365-
366-
fn visit_item(&mut self, item: &'hir hir::Item<'hir>) {
367-
(self.visit_hole_span)(item.span);
354+
/// We override `visit_nested_item` instead of `visit_item` because we
355+
/// only need the item's span, not the item itself.
356+
fn visit_nested_item(&mut self, id: hir::ItemId) -> Self::Result {
357+
let span = self.tcx.def_span(id.owner_id.def_id);
358+
(self.visit_hole_span)(span);
368359
// Having visited this item, we don't care about its children,
369360
// so don't call `walk_item`.
370361
}

0 commit comments

Comments
 (0)