From 3a225c77bba8576333924e7435493cb4d4e0cbaf Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Tue, 3 Oct 2017 19:44:58 +1000 Subject: [PATCH] Rename FileMap::path and change to an Option --- src/librustc/ich/impls_syntax.rs | 2 +- src/libsyntax/codemap.rs | 18 ++++++++++++------ src/libsyntax/ext/expand.rs | 4 ++-- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax_pos/lib.rs | 11 ++++++----- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 87e41d30e5d..799e790b85f 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -354,7 +354,7 @@ impl<'gcx> HashStable> for FileMap { let FileMap { ref name, name_was_remapped, - path: _, + unmapped_path: _, crate_of_origin, // Do not hash the source as it is not encoded src: _, diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 79262580858..efaa5e5e3da 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -167,11 +167,16 @@ impl CodeMap { // Note that filename may not be a valid path, eg it may be `` etc, // but this is okay because the directory determined by `path.pop()` will // be empty, so the working directory will be used. - let path = PathBuf::from(filename.clone()); + let unmapped_path = PathBuf::from(filename.clone()); let (filename, was_remapped) = self.path_mapping.map_prefix(filename); - let filemap = - Rc::new(FileMap::new(filename, was_remapped, path, src, Pos::from_usize(start_pos))); + let filemap = Rc::new(FileMap::new( + filename, + was_remapped, + unmapped_path, + src, + Pos::from_usize(start_pos), + )); files.push(filemap.clone()); @@ -223,7 +228,7 @@ impl CodeMap { let filemap = Rc::new(FileMap { name: filename, name_was_remapped, - path: PathBuf::new(), + unmapped_path: None, crate_of_origin, src: None, src_hash, @@ -353,8 +358,9 @@ impl CodeMap { self.lookup_char_pos(sp.lo()).file.name.clone() } - pub fn span_to_path(&self, sp: Span) -> PathBuf { - self.lookup_char_pos(sp.lo()).file.path.clone() + pub fn span_to_unmapped_path(&self, sp: Span) -> PathBuf { + self.lookup_char_pos(sp.lo()).file.unmapped_path.clone() + .expect("CodeMap::span_to_unmapped_path called for imported FileMap?") } pub fn span_to_lines(&self, sp: Span) -> FileLinesResult { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c4727b6eda5..614c4a10e6d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -199,7 +199,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { self.cx.crate_root = std_inject::injected_crate_name(&krate); let mut module = ModuleData { mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)], - directory: self.cx.codemap().span_to_path(krate.span), + directory: self.cx.codemap().span_to_unmapped_path(krate.span), }; module.directory.pop(); self.cx.current_expansion.module = Rc::new(module); @@ -951,7 +951,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { module.directory.push(&*item.ident.name.as_str()); } } else { - let mut path = self.cx.parse_sess.codemap().span_to_path(inner); + let mut path = self.cx.parse_sess.codemap().span_to_unmapped_path(inner); let directory_ownership = match path.file_name().unwrap().to_str() { Some("mod.rs") => DirectoryOwnership::Owned, _ => DirectoryOwnership::UnownedViaMod(false), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 8bc7f055676..86657e675b2 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -197,7 +197,7 @@ fn res_rel_file(cx: &mut ExtCtxt, sp: syntax_pos::Span, arg: &Path) -> PathBuf { // after macro expansion (that is, they are unhygienic). if !arg.is_absolute() { let callsite = sp.source_callsite(); - let mut path = cx.codemap().span_to_path(callsite); + let mut path = cx.codemap().span_to_unmapped_path(callsite); path.pop(); path.push(arg); path diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bd1d4241be0..65dabe98a06 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -525,7 +525,7 @@ impl<'a> Parser<'a> { if let Some(directory) = directory { parser.directory = directory; } else if parser.span != syntax_pos::DUMMY_SP { - parser.directory.path = sess.codemap().span_to_path(parser.span); + parser.directory.path = sess.codemap().span_to_unmapped_path(parser.span); parser.directory.path.pop(); } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 0d910cc04f6..2000db9703c 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -502,8 +502,9 @@ pub struct FileMap { pub name: FileName, /// True if the `name` field above has been modified by -Zremap-path-prefix pub name_was_remapped: bool, - /// The path of the file that the source came from. - pub path: PathBuf, + /// The unmapped path of the file that the source came from. + /// Set to `None` if the FileMap was imported from an external crate. + pub unmapped_path: Option, /// Indicates which crate this FileMap was imported from. pub crate_of_origin: u32, /// The complete source code @@ -629,7 +630,7 @@ impl Decodable for FileMap { Ok(FileMap { name, name_was_remapped, - path: PathBuf::new(), + unmapped_path: None, // `crate_of_origin` has to be set by the importer. // This value matches up with rustc::hir::def_id::INVALID_CRATE. // That constant is not available here unfortunately :( @@ -655,7 +656,7 @@ impl fmt::Debug for FileMap { impl FileMap { pub fn new(name: FileName, name_was_remapped: bool, - path: PathBuf, + unmapped_path: PathBuf, mut src: String, start_pos: BytePos) -> FileMap { remove_bom(&mut src); @@ -669,7 +670,7 @@ impl FileMap { FileMap { name, name_was_remapped, - path, + unmapped_path: Some(unmapped_path), crate_of_origin: 0, src: Some(Rc::new(src)), src_hash,