mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Fix --pretty=expanded with --remap-path-prefix
Per https://github.com/rust-lang/rust/issues/80832, using --pretty=expanded and --remap-path-prefix results in an ICE. This is becasue the session source files table is stored in remapped form, whereas --pretty-expanded looks up unremapped files. This remaps the path prefixes before lookup.
This commit is contained in:
parent
6184f23950
commit
67978d56c1
@ -363,8 +363,15 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
|
||||
|
||||
fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
|
||||
let src_name = input.source_name();
|
||||
let src =
|
||||
String::clone(&sess.source_map().get_source_file(&src_name).unwrap().src.as_ref().unwrap());
|
||||
let src = String::clone(
|
||||
&sess
|
||||
.source_map()
|
||||
.get_source_file(&src_name)
|
||||
.expect("get_source_file")
|
||||
.src
|
||||
.as_ref()
|
||||
.expect("src"),
|
||||
);
|
||||
(src, src_name)
|
||||
}
|
||||
|
||||
|
@ -870,8 +870,10 @@ impl SourceMap {
|
||||
}
|
||||
|
||||
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> {
|
||||
// Remap filename before lookup
|
||||
let filename = self.path_mapping().map_filename_prefix(filename).0;
|
||||
for sf in self.files.borrow().source_files.iter() {
|
||||
if *filename == sf.name {
|
||||
if filename == sf.name {
|
||||
return Some(sf.clone());
|
||||
}
|
||||
}
|
||||
@ -1039,4 +1041,15 @@ impl FilePathMapping {
|
||||
|
||||
(path, false)
|
||||
}
|
||||
|
||||
fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) {
|
||||
match file {
|
||||
FileName::Real(realfile) => {
|
||||
let path = realfile.local_path();
|
||||
let (path, mapped) = self.map_prefix(path.to_path_buf());
|
||||
(FileName::Real(RealFileName::Named(path)), mapped)
|
||||
}
|
||||
other => (other.clone(), false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user