@@ -314,21 +314,27 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
314
314
}
315
315
316
316
fn make_coverage_hir_info ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> mir:: coverage:: HirInfo {
317
- let source_map = tcx. sess . source_map ( ) ;
318
- let ( some_fn_sig, hir_body) = fn_sig_and_body ( tcx, def_id) ;
317
+ let ( maybe_fn_sig, hir_body) = fn_sig_and_body ( tcx, def_id) ;
319
318
319
+ let function_source_hash = hash_mir_source ( tcx, hir_body) ;
320
320
let body_span = get_body_span ( tcx, hir_body, def_id) ;
321
321
322
- let source_file = source_map . lookup_source_file ( body_span . lo ( ) ) ;
323
- let fn_sig_span = match some_fn_sig . filter ( |fn_sig| {
324
- fn_sig . span . eq_ctxt ( body_span )
325
- && Lrc :: ptr_eq ( & source_file , & source_map . lookup_source_file ( fn_sig . span . lo ( ) ) )
326
- } ) {
327
- Some ( fn_sig ) => fn_sig . span . with_hi ( body_span . lo ( ) ) ,
328
- None => body_span . shrink_to_lo ( ) ,
322
+ let spans_are_compatible = {
323
+ let source_map = tcx . sess . source_map ( ) ;
324
+ | a : Span , b : Span | {
325
+ a . eq_ctxt ( b )
326
+ && source_map . lookup_source_file_idx ( a . lo ( ) )
327
+ == source_map . lookup_source_file_idx ( b . lo ( ) )
328
+ }
329
329
} ;
330
330
331
- let function_source_hash = hash_mir_source ( tcx, hir_body) ;
331
+ let fn_sig_span = if let Some ( fn_sig) = maybe_fn_sig
332
+ && spans_are_compatible ( fn_sig. span , body_span)
333
+ {
334
+ fn_sig. span . with_hi ( body_span. lo ( ) )
335
+ } else {
336
+ body_span. shrink_to_lo ( )
337
+ } ;
332
338
333
339
mir:: coverage:: HirInfo { function_source_hash, fn_sig_span, body_span }
334
340
}
0 commit comments