Skip to content

Commit 90fce80

Browse files
Add debug tracing to FilePathMapping::map_prefix
1 parent 77972d2 commit 90fce80

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

compiler/rustc_span/src/source_map.rs

+34-19
Original file line numberDiff line numberDiff line change
@@ -1098,28 +1098,43 @@ impl FilePathMapping {
10981098
/// The return value is the remapped path and a boolean indicating whether
10991099
/// the path was affected by the mapping.
11001100
pub fn map_prefix(&self, path: PathBuf) -> (PathBuf, bool) {
1101-
// NOTE: We are iterating over the mapping entries from last to first
1102-
// because entries specified later on the command line should
1103-
// take precedence.
1104-
for &(ref from, ref to) in self.mapping.iter().rev() {
1105-
if let Ok(rest) = path.strip_prefix(from) {
1106-
let remapped = if rest.as_os_str().is_empty() {
1107-
// This is subtle, joining an empty path onto e.g. `foo/bar` will
1108-
// result in `foo/bar/`, that is, there'll be an additional directory
1109-
// separator at the end. This can lead to duplicated directory separators
1110-
// in remapped paths down the line.
1111-
// So, if we have an exact match, we just return that without a call
1112-
// to `Path::join()`.
1113-
to.clone()
1114-
} else {
1115-
to.join(rest)
1116-
};
1101+
if path.as_os_str().is_empty() {
1102+
return (path, false);
1103+
}
11171104

1118-
return (remapped, true);
1105+
return remap_path_prefix(&self.mapping, path);
1106+
1107+
#[instrument(level = "debug", skip(mapping))]
1108+
fn remap_path_prefix(mapping: &[(PathBuf, PathBuf)], path: PathBuf) -> (PathBuf, bool) {
1109+
// NOTE: We are iterating over the mapping entries from last to first
1110+
// because entries specified later on the command line should
1111+
// take precedence.
1112+
for &(ref from, ref to) in mapping.iter().rev() {
1113+
debug!("Trying to apply {:?} => {:?}", from, to);
1114+
1115+
if let Ok(rest) = path.strip_prefix(from) {
1116+
let remapped = if rest.as_os_str().is_empty() {
1117+
// This is subtle, joining an empty path onto e.g. `foo/bar` will
1118+
// result in `foo/bar/`, that is, there'll be an additional directory
1119+
// separator at the end. This can lead to duplicated directory separators
1120+
// in remapped paths down the line.
1121+
// So, if we have an exact match, we just return that without a call
1122+
// to `Path::join()`.
1123+
to.clone()
1124+
} else {
1125+
to.join(rest)
1126+
};
1127+
debug!("Match - remapped {:?} => {:?}", path, remapped);
1128+
1129+
return (remapped, true);
1130+
} else {
1131+
debug!("No match - prefix {:?} does not match {:?}", from, path);
1132+
}
11191133
}
1120-
}
11211134

1122-
(path, false)
1135+
debug!("Path {:?} was not remapped", path);
1136+
(path, false)
1137+
}
11231138
}
11241139

11251140
fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) {

0 commit comments

Comments
 (0)