@@ -13,7 +13,6 @@ use self::spans::CoverageSpans;
13
13
14
14
use crate :: MirPass ;
15
15
16
- use rustc_data_structures:: sync:: Lrc ;
17
16
use rustc_middle:: hir;
18
17
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
19
18
use rustc_middle:: mir:: coverage:: * ;
@@ -317,23 +316,27 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
317
316
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
318
317
// to HIR for it.
319
318
320
- let source_map = tcx. sess . source_map ( ) ;
321
-
322
319
let hir_node = tcx. hir_node_by_def_id ( def_id) ;
323
320
let ( _, fn_body_id) =
324
321
hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
325
322
let hir_body = tcx. hir ( ) . body ( fn_body_id) ;
326
323
327
324
let body_span = get_body_span ( tcx, hir_body, def_id) ;
328
325
329
- let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
330
- let fn_sig_span = match hir_node. fn_sig ( ) . filter ( |fn_sig| {
331
- fn_sig. span . eq_ctxt ( body_span)
332
- && Lrc :: ptr_eq ( & source_file, & source_map. lookup_source_file ( fn_sig. span . lo ( ) ) )
333
- } ) {
334
- Some ( fn_sig) => fn_sig. span . with_hi ( body_span. lo ( ) ) ,
335
- None => body_span. shrink_to_lo ( ) ,
336
- } ;
326
+ // The actual signature span is only used if it has the same context and
327
+ // filename as the body.
328
+ let maybe_fn_sig_span = hir_node. fn_sig ( ) . map ( |fn_sig| fn_sig. span ) ;
329
+ let fn_sig_span = maybe_fn_sig_span
330
+ . filter ( |& fn_sig_span| {
331
+ let source_map = tcx. sess . source_map ( ) ;
332
+ let file_idx = |span : Span | source_map. lookup_source_file_idx ( span. lo ( ) ) ;
333
+
334
+ fn_sig_span. eq_ctxt ( body_span) && file_idx ( fn_sig_span) == file_idx ( body_span)
335
+ } )
336
+ // If so, extend it to the start of the body span.
337
+ . map ( |fn_sig_span| fn_sig_span. with_hi ( body_span. lo ( ) ) )
338
+ // Otherwise, create a dummy signature span at the start of the body.
339
+ . unwrap_or_else ( || body_span. shrink_to_lo ( ) ) ;
337
340
338
341
let function_source_hash = hash_mir_source ( tcx, hir_body) ;
339
342
0 commit comments