diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index d9bbb03129975..1c243f8bd5148 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -509,11 +509,20 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let working_dir = &self.tcx.sess.opts.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(joined) + } } RealFileName::Remapped { local_path: _, virtual_name } => { // If working_dir has been remapped, then we emit diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile new file mode 100644 index 0000000000000..86785c59509df --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -0,0 +1,9 @@ +-include ../tools.mk + +# ignore-windows + +# Checks if remapping works if the remap-from string contains path to the working directory plus more +all: + $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs + grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 + ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 diff --git a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs new file mode 100644 index 0000000000000..019c786a9023e --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs @@ -0,0 +1,3 @@ +pub fn lib() { + panic!("calm"); +}