Skip to content

Commit fc142eb

Browse files
committed
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.
1 parent 2f8d1a8 commit fc142eb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: 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)