Skip to content

Commit 3a225c7

Browse files
committed
Rename FileMap::path and change to an Option
1 parent c27a82f commit 3a225c7

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

src/librustc/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for FileMap {
354354
let FileMap {
355355
ref name,
356356
name_was_remapped,
357-
path: _,
357+
unmapped_path: _,
358358
crate_of_origin,
359359
// Do not hash the source as it is not encoded
360360
src: _,

src/libsyntax/codemap.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,16 @@ impl CodeMap {
167167
// Note that filename may not be a valid path, eg it may be `<anon>` etc,
168168
// but this is okay because the directory determined by `path.pop()` will
169169
// be empty, so the working directory will be used.
170-
let path = PathBuf::from(filename.clone());
170+
let unmapped_path = PathBuf::from(filename.clone());
171171

172172
let (filename, was_remapped) = self.path_mapping.map_prefix(filename);
173-
let filemap =
174-
Rc::new(FileMap::new(filename, was_remapped, path, 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+
));
175180

176181
files.push(filemap.clone());
177182

@@ -223,7 +228,7 @@ impl CodeMap {
223228
let filemap = Rc::new(FileMap {
224229
name: filename,
225230
name_was_remapped,
226-
path: PathBuf::new(),
231+
unmapped_path: None,
227232
crate_of_origin,
228233
src: None,
229234
src_hash,
@@ -353,8 +358,9 @@ impl CodeMap {
353358
self.lookup_char_pos(sp.lo()).file.name.clone()
354359
}
355360

356-
pub fn span_to_path(&self, sp: Span) -> PathBuf {
357-
self.lookup_char_pos(sp.lo()).file.path.clone()
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?")
358364
}
359365

360366
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {

src/libsyntax/ext/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
199199
self.cx.crate_root = std_inject::injected_crate_name(&krate);
200200
let mut module = ModuleData {
201201
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
202-
directory: self.cx.codemap().span_to_path(krate.span),
202+
directory: self.cx.codemap().span_to_unmapped_path(krate.span),
203203
};
204204
module.directory.pop();
205205
self.cx.current_expansion.module = Rc::new(module);
@@ -951,7 +951,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
951951
module.directory.push(&*item.ident.name.as_str());
952952
}
953953
} else {
954-
let mut path = self.cx.parse_sess.codemap().span_to_path(inner);
954+
let mut path = self.cx.parse_sess.codemap().span_to_unmapped_path(inner);
955955
let directory_ownership = match path.file_name().unwrap().to_str() {
956956
Some("mod.rs") => DirectoryOwnership::Owned,
957957
_ => DirectoryOwnership::UnownedViaMod(false),

src/libsyntax/ext/source_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn res_rel_file(cx: &mut ExtCtxt, sp: syntax_pos::Span, arg: &Path) -> PathBuf {
197197
// after macro expansion (that is, they are unhygienic).
198198
if !arg.is_absolute() {
199199
let callsite = sp.source_callsite();
200-
let mut path = cx.codemap().span_to_path(callsite);
200+
let mut path = cx.codemap().span_to_unmapped_path(callsite);
201201
path.pop();
202202
path.push(arg);
203203
path

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'a> Parser<'a> {
525525
if let Some(directory) = directory {
526526
parser.directory = directory;
527527
} else if parser.span != syntax_pos::DUMMY_SP {
528-
parser.directory.path = sess.codemap().span_to_path(parser.span);
528+
parser.directory.path = sess.codemap().span_to_unmapped_path(parser.span);
529529
parser.directory.path.pop();
530530
}
531531

src/libsyntax_pos/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,9 @@ pub struct FileMap {
502502
pub name: FileName,
503503
/// True if the `name` field above has been modified by -Zremap-path-prefix
504504
pub name_was_remapped: bool,
505-
/// The path of the file that the source came from.
506-
pub path: PathBuf,
505+
/// The unmapped path of the file that the source came from.
506+
/// Set to `None` if the FileMap was imported from an external crate.
507+
pub unmapped_path: Option<PathBuf>,
507508
/// Indicates which crate this FileMap was imported from.
508509
pub crate_of_origin: u32,
509510
/// The complete source code
@@ -629,7 +630,7 @@ impl Decodable for FileMap {
629630
Ok(FileMap {
630631
name,
631632
name_was_remapped,
632-
path: PathBuf::new(),
633+
unmapped_path: None,
633634
// `crate_of_origin` has to be set by the importer.
634635
// This value matches up with rustc::hir::def_id::INVALID_CRATE.
635636
// That constant is not available here unfortunately :(
@@ -655,7 +656,7 @@ impl fmt::Debug for FileMap {
655656
impl FileMap {
656657
pub fn new(name: FileName,
657658
name_was_remapped: bool,
658-
path: PathBuf,
659+
unmapped_path: PathBuf,
659660
mut src: String,
660661
start_pos: BytePos) -> FileMap {
661662
remove_bom(&mut src);
@@ -669,7 +670,7 @@ impl FileMap {
669670
FileMap {
670671
name,
671672
name_was_remapped,
672-
path,
673+
unmapped_path: Some(unmapped_path),
673674
crate_of_origin: 0,
674675
src: Some(Rc::new(src)),
675676
src_hash,

0 commit comments

Comments
 (0)