Skip to content

Commit 7ce8246

Browse files
authored
Rollup merge of #80859 - jsgf:fix-pretty-remap, r=davidtwco
Fix --pretty=expanded with --remap-path-prefix Per #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. ~~There don't appear to be any existing tests for --pretty=expanded; I'll look into adding some.~~ Never mind, found the pretty tests. Fixes #80832
2 parents 330e196 + d7ce9d5 commit 7ce8246

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

compiler/rustc_driver/src/pretty.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,15 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
363363

364364
fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
365365
let src_name = input.source_name();
366-
let src =
367-
String::clone(&sess.source_map().get_source_file(&src_name).unwrap().src.as_ref().unwrap());
366+
let src = String::clone(
367+
&sess
368+
.source_map()
369+
.get_source_file(&src_name)
370+
.expect("get_source_file")
371+
.src
372+
.as_ref()
373+
.expect("src"),
374+
);
368375
(src, src_name)
369376
}
370377

compiler/rustc_span/src/source_map.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,10 @@ impl SourceMap {
872872
}
873873

874874
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> {
875+
// Remap filename before lookup
876+
let filename = self.path_mapping().map_filename_prefix(filename).0;
875877
for sf in self.files.borrow().source_files.iter() {
876-
if *filename == sf.name {
878+
if filename == sf.name {
877879
return Some(sf.clone());
878880
}
879881
}
@@ -1041,4 +1043,15 @@ impl FilePathMapping {
10411043

10421044
(path, false)
10431045
}
1046+
1047+
fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) {
1048+
match file {
1049+
FileName::Real(realfile) => {
1050+
let path = realfile.local_path();
1051+
let (path, mapped) = self.map_prefix(path.to_path_buf());
1052+
(FileName::Real(RealFileName::Named(path)), mapped)
1053+
}
1054+
other => (other.clone(), false),
1055+
}
1056+
}
10441057
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#[prelude_import]
4+
use ::std::prelude::v1::*;
5+
#[macro_use]
6+
extern crate std;
7+
// Test for issue 80832
8+
//
9+
// pretty-mode:expanded
10+
// pp-exact:expanded-and-path-remap-80832.pp
11+
// compile-flags: --remap-path-prefix {{src-base}}=the/src
12+
13+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Test for issue 80832
2+
//
3+
// pretty-mode:expanded
4+
// pp-exact:expanded-and-path-remap-80832.pp
5+
// compile-flags: --remap-path-prefix {{src-base}}=the/src
6+
7+
fn main() {}

0 commit comments

Comments
 (0)