From 67978d56c11006a10d286153226f18e18367aa32 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 9 Jan 2021 16:04:48 -0800 Subject: [PATCH 1/2] 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. --- compiler/rustc_driver/src/pretty.rs | 11 +++++++++-- compiler/rustc_span/src/source_map.rs | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 305fa838afa..b7edc24bc4a 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -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) } diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index fefc0cb48dd..c864e0b4637 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -870,8 +870,10 @@ impl SourceMap { } pub fn get_source_file(&self, filename: &FileName) -> Option> { + // 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), + } + } } From d7ce9d5b6d43a78cc6ac47d653b372fbada01edc Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 9 Jan 2021 18:45:19 -0800 Subject: [PATCH 2/2] test for issue 80832 --- src/test/pretty/expanded-and-path-remap-80832.pp | 13 +++++++++++++ src/test/pretty/expanded-and-path-remap-80832.rs | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/pretty/expanded-and-path-remap-80832.pp create mode 100644 src/test/pretty/expanded-and-path-remap-80832.rs diff --git a/src/test/pretty/expanded-and-path-remap-80832.pp b/src/test/pretty/expanded-and-path-remap-80832.pp new file mode 100644 index 00000000000..6dbc19e9d9c --- /dev/null +++ b/src/test/pretty/expanded-and-path-remap-80832.pp @@ -0,0 +1,13 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::v1::*; +#[macro_use] +extern crate std; +// Test for issue 80832 +// +// pretty-mode:expanded +// pp-exact:expanded-and-path-remap-80832.pp +// compile-flags: --remap-path-prefix {{src-base}}=the/src + +fn main() { } diff --git a/src/test/pretty/expanded-and-path-remap-80832.rs b/src/test/pretty/expanded-and-path-remap-80832.rs new file mode 100644 index 00000000000..f48441fbc57 --- /dev/null +++ b/src/test/pretty/expanded-and-path-remap-80832.rs @@ -0,0 +1,7 @@ +// Test for issue 80832 +// +// pretty-mode:expanded +// pp-exact:expanded-and-path-remap-80832.pp +// compile-flags: --remap-path-prefix {{src-base}}=the/src + +fn main() {}