From 97e69d13e1d261685d3df6d9cf21613bbdfb3d75 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 3 Nov 2025 19:29:36 +0100 Subject: [PATCH] tidy: Fix false positives with absolute repo paths in `pal.rs` `check()` Fixes the bug: 1. git clone https://github.com/rust-lang/rust.git rust-improve-tests 2. cd rust-improve-tests 3. ./x test tidy Expected: No tidy errors found Actual: ``` thread 'pal (library)' (837175) panicked at src/tools/tidy/src/pal.rs:100:5: assertion failed: saw_target_arch ``` Since the git checkout dir contains the word "tests", the `pal.rs` `check()` used to erroneously ignore all paths. --- src/tools/tidy/src/pal.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index dfca2cda9a0f8..f03dde6257d76 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -68,14 +68,20 @@ const EXCEPTION_PATHS: &[&str] = &[ "library/std/src/io/error.rs", // Repr unpacked needed for UEFI ]; -pub fn check(path: &Path, tidy_ctx: TidyCtx) { - let mut check = tidy_ctx.start_check(CheckId::new("pal").path(path)); +pub fn check(library_path: &Path, tidy_ctx: TidyCtx) { + let mut check = tidy_ctx.start_check(CheckId::new("pal").path(library_path)); + + let root_path = library_path.parent().unwrap(); + // Let's double-check that this is the root path by making sure it has `x.py`. + assert!(root_path.join("x.py").is_file()); // Sanity check that the complex parsing here works. let mut saw_target_arch = false; let mut saw_cfg_bang = false; - walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| { + walk(library_path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| { let file = entry.path(); + // We don't want the absolute path to matter, so make it relative. + let file = file.strip_prefix(root_path).unwrap(); let filestr = file.to_string_lossy().replace("\\", "/"); if !filestr.ends_with(".rs") { return;