Skip to content

Commit

Permalink
Rename FileMap::path and change to an Option
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Oct 3, 2017
1 parent c27a82f commit 3a225c7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> 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: _,
Expand Down
18 changes: 12 additions & 6 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,16 @@ impl CodeMap {
// 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 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());

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
11 changes: 6 additions & 5 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// Indicates which crate this FileMap was imported from.
pub crate_of_origin: u32,
/// The complete source code
Expand Down Expand Up @@ -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 :(
Expand All @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 3a225c7

Please sign in to comment.