@@ -162,9 +162,21 @@ impl CodeMap {
162162 let start_pos = self . next_start_pos ( ) ;
163163 let mut files = self . files . borrow_mut ( ) ;
164164
165+ // The path is used to determine the directory for loading submodules and
166+ // include files, so it must be before remapping.
167+ // Note that filename may not be a valid path, eg it may be `<anon>` etc,
168+ // but this is okay because the directory determined by `path.pop()` will
169+ // be empty, so the working directory will be used.
170+ let unmapped_path = PathBuf :: from ( filename. clone ( ) ) ;
171+
165172 let ( filename, was_remapped) = self . path_mapping . map_prefix ( filename) ;
166- let filemap =
167- Rc :: new ( FileMap :: new ( filename, was_remapped, src, Pos :: from_usize ( start_pos) ) ) ;
173+ let filemap = Rc :: new ( FileMap :: new (
174+ filename,
175+ was_remapped,
176+ unmapped_path,
177+ src,
178+ Pos :: from_usize ( start_pos) ,
179+ ) ) ;
168180
169181 files. push ( filemap. clone ( ) ) ;
170182
@@ -216,6 +228,7 @@ impl CodeMap {
216228 let filemap = Rc :: new ( FileMap {
217229 name : filename,
218230 name_was_remapped,
231+ unmapped_path : None ,
219232 crate_of_origin,
220233 src : None ,
221234 src_hash,
@@ -342,7 +355,12 @@ impl CodeMap {
342355 }
343356
344357 pub fn span_to_filename ( & self , sp : Span ) -> FileName {
345- self . lookup_char_pos ( sp. lo ( ) ) . file . name . to_string ( )
358+ self . lookup_char_pos ( sp. lo ( ) ) . file . name . clone ( )
359+ }
360+
361+ pub fn span_to_unmapped_path ( & self , sp : Span ) -> PathBuf {
362+ self . lookup_char_pos ( sp. lo ( ) ) . file . unmapped_path . clone ( )
363+ . expect ( "CodeMap::span_to_unmapped_path called for imported FileMap?" )
346364 }
347365
348366 pub fn span_to_lines ( & self , sp : Span ) -> FileLinesResult {
0 commit comments