From 3614bd3c45a8d0e5f27c0736e8966f6456a5cd75 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 29 Apr 2022 19:36:02 +0200 Subject: Fix duplicate directory separator in --remap-path-prefix. --- compiler/rustc_span/src/source_map.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_span/src/source_map.rs') diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 95177102dcf..460b5c18fc1 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -1102,7 +1102,19 @@ impl FilePathMapping { // take precedence. for &(ref from, ref to) in self.mapping.iter().rev() { if let Ok(rest) = path.strip_prefix(from) { - return (to.join(rest), true); + let remapped = if rest.as_os_str().is_empty() { + // This is subtle, joining an empty path onto e.g. `foo/bar` will + // result in `foo/bar/`, that is, there'll be an additional directory + // separator at the end. This can lead to duplicated directory separators + // in remapped paths down the line. + // So, if we have an exact match, we just return that without a call + // to `Path::join()`. + to.clone() + } else { + to.join(rest) + }; + + return (remapped, true); } } -- cgit 1.4.1-3-g733a5