Skip to content

Commit

Permalink
Rollup merge of rust-lang#94582 - nnethercote:fix-x-fmt-bug, r=Mark-S…
Browse files Browse the repository at this point in the history
…imulacrum

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`
  • Loading branch information
Dylan-DPC authored Mar 4, 2022
2 parents 62ae30d + fc142eb commit 1da83f1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/bootstrap/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
});
for untracked_path in untracked_paths {
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
// The leading `/` makes it an exact match against the
// repository root, rather than a glob. Without that, if you
// have `foo.rs` in the repository root it will also match
// against anything like `compiler/rustc_foo/src/foo.rs`,
// preventing the latter from being formatted.
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
}
} else {
eprintln!("Not in git tree. Skipping git-aware format checks");
Expand Down

0 comments on commit 1da83f1

Please sign in to comment.