@@ -667,7 +667,12 @@ pub trait PrettyPrinter<'tcx>:
667667 if let Some ( did) = did. as_local ( ) {
668668 let hir_id = self . tcx ( ) . hir ( ) . local_def_id_to_hir_id ( did) ;
669669 let span = self . tcx ( ) . hir ( ) . span ( hir_id) ;
670- p ! ( write( "@{}" , self . tcx( ) . sess. source_map( ) . span_to_string( span) ) ) ;
670+ p ! ( write(
671+ "@{}" ,
672+ // This may end up in stderr diagnostics but it may also be emitted
673+ // into MIR. Hence we use the remapped path if available
674+ self . tcx( ) . sess. source_map( ) . span_to_embeddable_string( span)
675+ ) ) ;
671676 } else {
672677 p ! ( write( "@" ) , print_def_path( did, substs) ) ;
673678 }
@@ -702,7 +707,12 @@ pub trait PrettyPrinter<'tcx>:
702707 p ! ( "@" , print_def_path( did. to_def_id( ) , substs) ) ;
703708 } else {
704709 let span = self . tcx ( ) . hir ( ) . span ( hir_id) ;
705- p ! ( write( "@{}" , self . tcx( ) . sess. source_map( ) . span_to_string( span) ) ) ;
710+ p ! ( write(
711+ "@{}" ,
712+ // This may end up in stderr diagnostics but it may also be emitted
713+ // into MIR. Hence we use the remapped path if available
714+ self . tcx( ) . sess. source_map( ) . span_to_embeddable_string( span)
715+ ) ) ;
706716 }
707717 } else {
708718 p ! ( write( "@" ) , print_def_path( did, substs) ) ;
@@ -1407,7 +1417,13 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
14071417 if !self . empty_path {
14081418 write ! ( self , "::" ) ?;
14091419 }
1410- write ! ( self , "<impl at {}>" , self . tcx. sess. source_map( ) . span_to_string( span) ) ?;
1420+ write ! (
1421+ self ,
1422+ "<impl at {}>" ,
1423+ // This may end up in stderr diagnostics but it may also be emitted
1424+ // into MIR. Hence we use the remapped path if available
1425+ self . tcx. sess. source_map( ) . span_to_embeddable_string( span)
1426+ ) ?;
14111427 self . empty_path = false ;
14121428
14131429 return Ok ( self ) ;
0 commit comments