@@ -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:: * ;
@@ -306,23 +305,27 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
306
305
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
307
306
// to HIR for it.
308
307
309
- let source_map = tcx. sess . source_map ( ) ;
310
-
311
308
let hir_node = tcx. hir_node_by_def_id ( def_id) ;
312
309
let ( _, fn_body_id) =
313
310
hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
314
311
let hir_body = tcx. hir ( ) . body ( fn_body_id) ;
315
312
316
313
let body_span = get_body_span ( tcx, hir_body, def_id) ;
317
314
318
- let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
319
- let fn_sig_span = match hir_node. fn_sig ( ) . filter ( |fn_sig| {
320
- fn_sig. span . eq_ctxt ( body_span)
321
- && Lrc :: ptr_eq ( & source_file, & source_map. lookup_source_file ( fn_sig. span . lo ( ) ) )
322
- } ) {
323
- Some ( fn_sig) => fn_sig. span . with_hi ( body_span. lo ( ) ) ,
324
- None => body_span. shrink_to_lo ( ) ,
325
- } ;
315
+ // The actual signature span is only used if it has the same context and
316
+ // filename as the body.
317
+ let maybe_fn_sig_span = hir_node. fn_sig ( ) . map ( |fn_sig| fn_sig. span ) ;
318
+ let fn_sig_span = maybe_fn_sig_span
319
+ . filter ( |& fn_sig_span| {
320
+ let source_map = tcx. sess . source_map ( ) ;
321
+ let file_idx = |span : Span | source_map. lookup_source_file_idx ( span. lo ( ) ) ;
322
+
323
+ fn_sig_span. eq_ctxt ( body_span) && file_idx ( fn_sig_span) == file_idx ( body_span)
324
+ } )
325
+ // If so, extend it to the start of the body span.
326
+ . map ( |fn_sig_span| fn_sig_span. with_hi ( body_span. lo ( ) ) )
327
+ // Otherwise, create a dummy signature span at the start of the body.
328
+ . unwrap_or_else ( || body_span. shrink_to_lo ( ) ) ;
326
329
327
330
let function_source_hash = hash_mir_source ( tcx, hir_body) ;
328
331
0 commit comments