@@ -26,11 +26,11 @@ use rustc_middle::ty::fast_reject::{self, TreatParams};
26
26
use rustc_middle:: ty:: { AssocItemContainer , SymbolName } ;
27
27
use rustc_middle:: { bug, span_bug} ;
28
28
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder , opaque} ;
29
- use rustc_session:: config:: { CrateType , OptLevel , TargetModifier } ;
29
+ use rustc_session:: config:: { CrateType , OptLevel , RemapPathScopeComponents , TargetModifier } ;
30
30
use rustc_span:: hygiene:: HygieneEncodeContext ;
31
31
use rustc_span:: {
32
- ExternalSource , FileName , SourceFile , SpanData , SpanEncoder , StableSourceFileId , SyntaxContext ,
33
- sym,
32
+ ExternalSource , FileName , FileNameDisplayPreference , SourceFile , SpanData , SpanEncoder ,
33
+ StableSourceFileId , SyntaxContext , sym,
34
34
} ;
35
35
use tracing:: { debug, instrument, trace} ;
36
36
@@ -520,6 +520,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
520
520
let source_map = self . tcx . sess . source_map ( ) ;
521
521
let all_source_files = source_map. files ( ) ;
522
522
523
+ let filename_display_preference =
524
+ self . tcx . sess . filename_display_preference ( RemapPathScopeComponents :: DEBUGINFO ) ;
525
+
523
526
// By replacing the `Option` with `None`, we ensure that we can't
524
527
// accidentally serialize any more `Span`s after the source map encoding
525
528
// is done.
@@ -551,11 +554,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
551
554
552
555
match source_file. name {
553
556
FileName :: Real ( ref original_file_name) => {
554
- // FIXME: This should probably to conditionally remapped under
555
- // a RemapPathScopeComponents but which one?
556
- let adapted_file_name = source_map
557
- . path_mapping ( )
558
- . to_embeddable_absolute_path ( original_file_name. clone ( ) , working_directory) ;
557
+ let adapted_file_name =
558
+ if filename_display_preference == FileNameDisplayPreference :: Remapped {
559
+ source_map. path_mapping ( ) . to_embeddable_absolute_path (
560
+ original_file_name. clone ( ) ,
561
+ working_directory,
562
+ )
563
+ } else {
564
+ source_map. path_mapping ( ) . to_local_embeddable_absolute_path (
565
+ original_file_name. clone ( ) ,
566
+ working_directory,
567
+ )
568
+ } ;
559
569
560
570
adapted_source_file. name = FileName :: Real ( adapted_file_name) ;
561
571
}
0 commit comments