Rename FileMap::path and change to an Option

This commit is contained in:
Philip Craig 2017-10-03 19:44:58 +10:00
parent c27a82f193
commit 3a225c77bb
6 changed files with 23 additions and 16 deletions

View File

@ -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: _,

View File

@ -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());
@ -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 {

View File

@ -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),

View File

@ -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

View File

@ -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();
}

View File

@ -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
@ -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,