@@ -22,7 +22,7 @@ use rustc_middle::mir::{
22
22
TerminatorKind ,
23
23
} ;
24
24
use rustc_middle:: ty:: TyCtxt ;
25
- use rustc_span:: def_id:: { DefId , LocalDefId } ;
25
+ use rustc_span:: def_id:: LocalDefId ;
26
26
use rustc_span:: source_map:: SourceMap ;
27
27
use rustc_span:: { ExpnKind , Span , Symbol } ;
28
28
@@ -79,7 +79,7 @@ struct Instrumentor<'a, 'tcx> {
79
79
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
80
80
fn new ( tcx : TyCtxt < ' tcx > , mir_body : & ' a mut mir:: Body < ' tcx > ) -> Self {
81
81
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 ( ) ) ;
83
83
84
84
debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
85
85
@@ -313,12 +313,11 @@ struct ExtractedHirInfo {
313
313
body_span : Span ,
314
314
}
315
315
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 {
317
317
let source_map = tcx. sess . source_map ( ) ;
318
- let def_id = mir_body. source . def_id ( ) ;
319
318
let ( some_fn_sig, hir_body) = fn_sig_and_body ( tcx, def_id) ;
320
319
321
- let body_span = get_body_span ( tcx, hir_body, mir_body ) ;
320
+ let body_span = get_body_span ( tcx, hir_body, def_id ) ;
322
321
323
322
let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
324
323
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
336
335
337
336
fn fn_sig_and_body (
338
337
tcx : TyCtxt < ' _ > ,
339
- def_id : DefId ,
338
+ def_id : LocalDefId ,
340
339
) -> ( Option < & rustc_hir:: FnSig < ' _ > > , & rustc_hir:: Body < ' _ > ) {
341
340
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
342
341
// 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) ;
344
343
let ( _, fn_body_id) =
345
344
hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
346
345
( hir_node. fn_sig ( ) , tcx. hir ( ) . body ( fn_body_id) )
@@ -349,12 +348,11 @@ fn fn_sig_and_body(
349
348
fn get_body_span < ' tcx > (
350
349
tcx : TyCtxt < ' tcx > ,
351
350
hir_body : & rustc_hir:: Body < ' tcx > ,
352
- mir_body : & mir :: Body < ' tcx > ,
351
+ def_id : LocalDefId ,
353
352
) -> Span {
354
353
let mut body_span = hir_body. value . span ;
355
- let def_id = mir_body. source . def_id ( ) ;
356
354
357
- if tcx. is_closure ( def_id) {
355
+ if tcx. is_closure ( def_id. to_def_id ( ) ) {
358
356
// If the MIR function is a closure, and if the closure body span
359
357
// starts from a macro, but it's content is not in that macro, try
360
358
// to find a non-macro callsite, and instrument the spans there
0 commit comments