Skip to content

Commit 733a1a8

Browse files
authored
Rollup merge of #94582 - nnethercote:fix-x-fmt-bug, r=Mark-Simulacrum
Fix a bug in `x.py fmt` that prevents some files being formatted. If you have a file in the repository root with the same name as a file somewhere within a directory, the latter currently won't get formatted. I have experienced this multiple times and not understood what was happening; I finally figured out the problem today. This commit fixes the problem. r? ```@Mark-Simulacrum```
2 parents 72c0c08 + fc142eb commit 733a1a8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bootstrap/format.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
9797
});
9898
for untracked_path in untracked_paths {
9999
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
100-
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
100+
// The leading `/` makes it an exact match against the
101+
// repository root, rather than a glob. Without that, if you
102+
// have `foo.rs` in the repository root it will also match
103+
// against anything like `compiler/rustc_foo/src/foo.rs`,
104+
// preventing the latter from being formatted.
105+
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
101106
}
102107
} else {
103108
eprintln!("Not in git tree. Skipping git-aware format checks");

0 commit comments

Comments
 (0)