@@ -22,7 +22,7 @@ use rustc_middle::mir::{
2222 TerminatorKind ,
2323} ;
2424use rustc_middle:: ty:: TyCtxt ;
25- use rustc_span:: def_id:: { DefId , LocalDefId } ;
25+ use rustc_span:: def_id:: LocalDefId ;
2626use rustc_span:: source_map:: SourceMap ;
2727use rustc_span:: { ExpnKind , Span , Symbol } ;
2828
@@ -76,7 +76,7 @@ struct Instrumentor<'a, 'tcx> {
7676
7777impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
7878 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 ( ) ) ;
8080
8181 debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
8282
@@ -302,12 +302,11 @@ struct ExtractedHirInfo {
302302 body_span : Span ,
303303}
304304
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 {
306306 let source_map = tcx. sess . source_map ( ) ;
307- let def_id = mir_body. source . def_id ( ) ;
308307 let ( some_fn_sig, hir_body) = fn_sig_and_body ( tcx, def_id) ;
309308
310- let body_span = get_body_span ( tcx, hir_body, mir_body ) ;
309+ let body_span = get_body_span ( tcx, hir_body, def_id ) ;
311310
312311 let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
313312 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
325324
326325fn fn_sig_and_body (
327326 tcx : TyCtxt < ' _ > ,
328- def_id : DefId ,
327+ def_id : LocalDefId ,
329328) -> ( Option < & rustc_hir:: FnSig < ' _ > > , & rustc_hir:: Body < ' _ > ) {
330329 // FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
331330 // 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) ;
333332 let ( _, fn_body_id) =
334333 hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
335334 ( hir_node. fn_sig ( ) , tcx. hir ( ) . body ( fn_body_id) )
@@ -338,12 +337,11 @@ fn fn_sig_and_body(
338337fn get_body_span < ' tcx > (
339338 tcx : TyCtxt < ' tcx > ,
340339 hir_body : & rustc_hir:: Body < ' tcx > ,
341- mir_body : & mir :: Body < ' tcx > ,
340+ def_id : LocalDefId ,
342341) -> Span {
343342 let mut body_span = hir_body. value . span ;
344- let def_id = mir_body. source . def_id ( ) ;
345343
346- if tcx. is_closure ( def_id) {
344+ if tcx. is_closure ( def_id. to_def_id ( ) ) {
347345 // If the MIR function is a closure, and if the closure body span
348346 // starts from a macro, but it's content is not in that macro, try
349347 // to find a non-macro callsite, and instrument the spans there
0 commit comments