diff options
| author | bors <bors@rust-lang.org> | 2017-10-05 05:16:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-10-05 05:16:41 +0000 |
| commit | a0db04b62bde392fb9846d4a90e3973bab09147a (patch) | |
| tree | e7f3372b427ba3d0886b44b9767affc59b2a4874 /src/libsyntax | |
| parent | bd36dcf7aa2c45b47fe102376222667b0a903c23 (diff) | |
| parent | 9bbd7a3b3f2f713220f429bd15466135efa7f3b7 (diff) | |
| download | rust-a0db04b62bde392fb9846d4a90e3973bab09147a.tar.gz rust-a0db04b62bde392fb9846d4a90e3973bab09147a.zip | |
Auto merge of #44940 - philipc:remap-path, r=michaelwoerister
Don't use remapped path when loading modules and include files Fixes bug reported in https://github.com/rust-lang/rust/issues/41555#issuecomment-327866056. cc @michaelwoerister
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 |
4 files changed, 25 insertions, 9 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index cd4a6f921fe..efaa5e5e3da 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -162,9 +162,21 @@ impl CodeMap { let start_pos = self.next_start_pos(); let mut files = self.files.borrow_mut(); + // The path is used to determine the directory for loading submodules and + // include files, so it must be before remapping. + // Note that filename may not be a valid path, eg it may be `<anon>` etc, + // but this is okay because the directory determined by `path.pop()` will + // be empty, so the working directory will be used. + 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, 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()); @@ -216,6 +228,7 @@ impl CodeMap { let filemap = Rc::new(FileMap { name: filename, name_was_remapped, + unmapped_path: None, crate_of_origin, src: None, src_hash, @@ -342,7 +355,12 @@ impl CodeMap { } pub fn span_to_filename(&self, sp: Span) -> FileName { - self.lookup_char_pos(sp.lo()).file.name.to_string() + self.lookup_char_pos(sp.lo()).file.name.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 6e7a8203b61..614c4a10e6d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -35,7 +35,6 @@ use visit::Visitor; use std::collections::HashMap; use std::mem; -use std::path::PathBuf; use std::rc::Rc; macro_rules! expansions { @@ -200,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: PathBuf::from(self.cx.codemap().span_to_filename(krate.span)), + directory: self.cx.codemap().span_to_unmapped_path(krate.span), }; module.directory.pop(); self.cx.current_expansion.module = Rc::new(module); @@ -952,8 +951,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { module.directory.push(&*item.ident.name.as_str()); } } else { - let mut path = - PathBuf::from(self.cx.parse_sess.codemap().span_to_filename(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 18a262d139a..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 = PathBuf::from(&cx.codemap().span_to_filename(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 d5ba4b54d90..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 = PathBuf::from(sess.codemap().span_to_filename(parser.span)); + parser.directory.path = sess.codemap().span_to_unmapped_path(parser.span); parser.directory.path.pop(); } |
