@@ -127,30 +127,17 @@ pub struct StableSourceFileId(u128);
127127// StableSourceFileId, perhaps built atop source_file.name_hash.
128128impl StableSourceFileId {
129129 pub fn new ( source_file : & SourceFile ) -> StableSourceFileId {
130- StableSourceFileId :: new_from_pieces (
131- & source_file. name ,
132- source_file. name_was_remapped ,
133- source_file. unmapped_path . as_ref ( ) ,
134- )
130+ StableSourceFileId :: new_from_pieces ( & source_file. name , source_file. name_was_remapped )
135131 }
136132
137- fn new_from_pieces (
138- name : & FileName ,
139- name_was_remapped : bool ,
140- unmapped_path : Option < & FileName > ,
141- ) -> StableSourceFileId {
133+ fn new_from_pieces ( name : & FileName , name_was_remapped : bool ) -> StableSourceFileId {
142134 let mut hasher = StableHasher :: new ( ) ;
143135
144- if let FileName :: Real ( real_name) = name {
145- // rust-lang/rust#70924: Use the stable (virtualized) name when
146- // available. (We do not want artifacts from transient file system
147- // paths for libstd to leak into our build artifacts.)
148- real_name. stable_name ( ) . hash ( & mut hasher)
149- } else {
150- name. hash ( & mut hasher) ;
151- }
136+ // If name was virtualized, we need to take both the local path
137+ // and stablised path into account, in case two different paths were
138+ // mapped to the same
139+ name. hash ( & mut hasher) ;
152140 name_was_remapped. hash ( & mut hasher) ;
153- unmapped_path. hash ( & mut hasher) ;
154141
155142 StableSourceFileId ( hasher. finish ( ) )
156143 }
@@ -286,25 +273,21 @@ impl SourceMap {
286273 filename : FileName ,
287274 src : String ,
288275 ) -> Result < Lrc < SourceFile > , OffsetOverflowError > {
289- // We need to preserve the unmapped path is as it is
290- // used to determine the directory for loading submodules and include files.
291276 // Note that filename may not be a valid path, eg it may be `<anon>` etc,
292277 // but this is okay because the directory determined by `path.pop()` will
293278 // be empty, so the working directory will be used.
294- let ( mapped_filename , was_remapped) = self . path_mapping . map_filename_prefix ( & filename) ;
279+ let ( filename , was_remapped) = self . path_mapping . map_filename_prefix ( & filename) ;
295280
296- let file_id =
297- StableSourceFileId :: new_from_pieces ( & mapped_filename, was_remapped, Some ( & filename) ) ;
281+ let file_id = StableSourceFileId :: new_from_pieces ( & filename, was_remapped) ;
298282
299283 let lrc_sf = match self . source_file_by_stable_id ( file_id) {
300284 Some ( lrc_sf) => lrc_sf,
301285 None => {
302286 let start_pos = self . allocate_address_space ( src. len ( ) ) ?;
303287
304288 let source_file = Lrc :: new ( SourceFile :: new (
305- mapped_filename,
306- was_remapped,
307289 filename,
290+ was_remapped,
308291 src,
309292 Pos :: from_usize ( start_pos) ,
310293 self . hash_kind ,
@@ -368,7 +351,6 @@ impl SourceMap {
368351 let source_file = Lrc :: new ( SourceFile {
369352 name : filename,
370353 name_was_remapped : name_was_remapped || name_is_remapped,
371- unmapped_path : None ,
372354 src : None ,
373355 src_hash,
374356 external_src : Lock :: new ( ExternalSource :: Foreign {
@@ -459,14 +441,6 @@ impl SourceMap {
459441 self . lookup_char_pos ( sp. lo ( ) ) . file . name . clone ( )
460442 }
461443
462- pub fn span_to_unmapped_path ( & self , sp : Span ) -> FileName {
463- self . lookup_char_pos ( sp. lo ( ) )
464- . file
465- . unmapped_path
466- . clone ( )
467- . expect ( "`SourceMap::span_to_unmapped_path` called for imported `SourceFile`?" )
468- }
469-
470444 pub fn is_multiline ( & self , sp : Span ) -> bool {
471445 let lo = self . lookup_char_pos ( sp. lo ( ) ) ;
472446 let hi = self . lookup_char_pos ( sp. hi ( ) ) ;
0 commit comments