From 1ced98ac651510f1a614caf287fca88721c2b983 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 15 May 2021 19:36:42 +0100 Subject: [PATCH] Remap after prepending cwd --- compiler/rustc_metadata/src/rmeta/encoder.rs | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 29fcbffa0b9..1b7b851382e 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -497,11 +497,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let working_dir = &self.tcx.sess.working_dir; match working_dir { RealFileName::LocalPath(absolute) => { - // If working_dir has not been remapped, then we emit a - // LocalPath variant as it's likely to be a valid path - RealFileName::LocalPath( - Path::new(absolute).join(path_to_file), - ) + // Although neither working_dir or the file name were subject + // to path remapping, the concatenation between the two may + // be. Hence we need to do a remapping here. + let joined = Path::new(absolute).join(path_to_file); + let (joined, remapped) = + source_map.path_mapping().map_prefix(joined); + if remapped { + RealFileName::Remapped { + local_path: None, + virtual_name: joined, + } + } else { + RealFileName::LocalPath( + Path::new(absolute).join(path_to_file), + ) + } } RealFileName::Remapped { local_path: _, virtual_name } => { // If working_dir has been remapped, then we emit