about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-03-04 02:06:44 +0100
committerGitHub <noreply@github.com>2022-03-04 02:06:44 +0100
commit733a1a8ca42347a19c0d8a143fb090a9f0c2b810 (patch)
treee6bbca174e3d1b6c1a1c06d365ec2312456c2222
parent72c0c08445440aae001c028eda05de5467b507dc (diff)
parentfc142ebaf8cd18e2e9400e4ee9efb8a4331696d2 (diff)
downloadrust-733a1a8ca42347a19c0d8a143fb090a9f0c2b810.tar.gz
rust-733a1a8ca42347a19c0d8a143fb090a9f0c2b810.zip
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```
-rw-r--r--src/bootstrap/format.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bootstrap/format.rs b/src/bootstrap/format.rs
index 30fe6a7a446..530cc829320 100644
--- a/src/bootstrap/format.rs
+++ b/src/bootstrap/format.rs
@@ -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");