@@ -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
@@ -76,7 +76,7 @@ struct Instrumentor<'a, 'tcx> {
76
76
77
77
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
78
78
fn new ( tcx : TyCtxt < ' tcx > , mir_body : & ' a mut mir:: Body < ' tcx > ) -> Self {
79
- let hir_info = extract_hir_info ( tcx, mir_body) ;
79
+ let hir_info = extract_hir_info ( tcx, mir_body. source . def_id ( ) . expect_local ( ) ) ;
80
80
81
81
debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
82
82
@@ -302,12 +302,11 @@ struct ExtractedHirInfo {
302
302
body_span : Span ,
303
303
}
304
304
305
- fn extract_hir_info < ' tcx > ( tcx : TyCtxt < ' tcx > , mir_body : & mir :: Body < ' tcx > ) -> ExtractedHirInfo {
305
+ fn extract_hir_info < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> ExtractedHirInfo {
306
306
let source_map = tcx. sess . source_map ( ) ;
307
- let def_id = mir_body. source . def_id ( ) ;
308
307
let ( some_fn_sig, hir_body) = fn_sig_and_body ( tcx, def_id) ;
309
308
310
- let body_span = get_body_span ( tcx, hir_body, mir_body ) ;
309
+ let body_span = get_body_span ( tcx, hir_body, def_id ) ;
311
310
312
311
let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
313
312
let fn_sig_span = match some_fn_sig. filter ( |fn_sig| {
@@ -325,11 +324,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mir::Body<'tcx>) -> Extr
325
324
326
325
fn fn_sig_and_body (
327
326
tcx : TyCtxt < ' _ > ,
328
- def_id : DefId ,
327
+ def_id : LocalDefId ,
329
328
) -> ( Option < & rustc_hir:: FnSig < ' _ > > , & rustc_hir:: Body < ' _ > ) {
330
329
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
331
330
// to HIR for it.
332
- let hir_node = tcx. hir ( ) . get_if_local ( def_id) . expect ( "expected DefId is local" ) ;
331
+ let hir_node = tcx. hir_node_by_def_id ( def_id) ;
333
332
let ( _, fn_body_id) =
334
333
hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
335
334
( hir_node. fn_sig ( ) , tcx. hir ( ) . body ( fn_body_id) )
@@ -338,12 +337,11 @@ fn fn_sig_and_body(
338
337
fn get_body_span < ' tcx > (
339
338
tcx : TyCtxt < ' tcx > ,
340
339
hir_body : & rustc_hir:: Body < ' tcx > ,
341
- mir_body : & mir :: Body < ' tcx > ,
340
+ def_id : LocalDefId ,
342
341
) -> Span {
343
342
let mut body_span = hir_body. value . span ;
344
- let def_id = mir_body. source . def_id ( ) ;
345
343
346
- if tcx. is_closure ( def_id) {
344
+ if tcx. is_closure ( def_id. to_def_id ( ) ) {
347
345
// If the MIR function is a closure, and if the closure body span
348
346
// starts from a macro, but it's content is not in that macro, try
349
347
// to find a non-macro callsite, and instrument the spans there
0 commit comments