Skip to content

Commit e2f449b

Browse files
committed
coverage: Use LocalDefId in extract_hir_info
1 parent b9955fb commit e2f449b

File tree

1 file changed

+8
-10
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+8
-10
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::mir::{
2222
TerminatorKind,
2323
};
2424
use rustc_middle::ty::TyCtxt;
25-
use rustc_span::def_id::{DefId, LocalDefId};
25+
use rustc_span::def_id::LocalDefId;
2626
use rustc_span::source_map::SourceMap;
2727
use rustc_span::{ExpnKind, Span, Symbol};
2828

@@ -79,7 +79,7 @@ struct Instrumentor<'a, 'tcx> {
7979
impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
8080
fn new(tcx: TyCtxt<'tcx>, mir_body: &'a mut mir::Body<'tcx>) -> Self {
8181
let hir_info @ ExtractedHirInfo { function_source_hash, fn_sig_span, body_span } =
82-
extract_hir_info(tcx, mir_body);
82+
extract_hir_info(tcx, mir_body.source.def_id().expect_local());
8383

8484
debug!(?hir_info, "instrumenting {:?}", mir_body.source.def_id());
8585

@@ -313,12 +313,11 @@ struct ExtractedHirInfo {
313313
body_span: Span,
314314
}
315315

316-
fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> ExtractedHirInfo {
316+
fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHirInfo {
317317
let source_map = tcx.sess.source_map();
318-
let def_id = mir_body.source.def_id();
319318
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
320319

321-
let body_span = get_body_span(tcx, hir_body, mir_body);
320+
let body_span = get_body_span(tcx, hir_body, def_id);
322321

323322
let source_file = source_map.lookup_source_file(body_span.lo());
324323
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
@@ -336,11 +335,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> Extr
336335

337336
fn fn_sig_and_body(
338337
tcx: TyCtxt<'_>,
339-
def_id: DefId,
338+
def_id: LocalDefId,
340339
) -> (Option<&rustc_hir::FnSig<'_>>, &rustc_hir::Body<'_>) {
341340
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
342341
// to HIR for it.
343-
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
342+
let hir_node = tcx.hir_node_by_def_id(def_id);
344343
let (_, fn_body_id) =
345344
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
346345
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
@@ -349,12 +348,11 @@ fn fn_sig_and_body(
349348
fn get_body_span<'tcx>(
350349
tcx: TyCtxt<'tcx>,
351350
hir_body: &rustc_hir::Body<'tcx>,
352-
mir_body: &mir::Body<'tcx>,
351+
def_id: LocalDefId,
353352
) -> Span {
354353
let mut body_span = hir_body.value.span;
355-
let def_id = mir_body.source.def_id();
356354

357-
if tcx.is_closure(def_id) {
355+
if tcx.is_closure(def_id.to_def_id()) {
358356
// If the MIR function is a closure, and if the closure body span
359357
// starts from a macro, but it's content is not in that macro, try
360358
// to find a non-macro callsite, and instrument the spans there

0 commit comments

Comments
 (0)