Skip to content

Commit 161ba70

Browse files
authored
Rollup merge of #148451 - Enselic:tidy-fix, r=clubby789
tidy: Fix false positives with absolute repo paths in `pal.rs` `check()` Fixes this bug: #### Step-by-step 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 ``` #### Explanation Since the git checkout dir contains the word ["tests"](https://github.com/rust-lang/rust/blob/bf0ce4bc6816e3b9aaa52dc5fd47b8b5b2e0cd50/src/tools/tidy/src/pal.rs#L96), the `pal.rs` `check()` used to erroneously ignore all paths.
2 parents 5144cf8 + 97e69d1 commit 161ba70

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tools/tidy/src/pal.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ const EXCEPTION_PATHS: &[&str] = &[
6868
"library/std/src/io/error.rs", // Repr unpacked needed for UEFI
6969
];
7070

71-
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
72-
let mut check = tidy_ctx.start_check(CheckId::new("pal").path(path));
71+
pub fn check(library_path: &Path, tidy_ctx: TidyCtx) {
72+
let mut check = tidy_ctx.start_check(CheckId::new("pal").path(library_path));
73+
74+
let root_path = library_path.parent().unwrap();
75+
// Let's double-check that this is the root path by making sure it has `x.py`.
76+
assert!(root_path.join("x.py").is_file());
7377

7478
// Sanity check that the complex parsing here works.
7579
let mut saw_target_arch = false;
7680
let mut saw_cfg_bang = false;
77-
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
81+
walk(library_path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
7882
let file = entry.path();
83+
// We don't want the absolute path to matter, so make it relative.
84+
let file = file.strip_prefix(root_path).unwrap();
7985
let filestr = file.to_string_lossy().replace("\\", "/");
8086
if !filestr.ends_with(".rs") {
8187
return;

0 commit comments

Comments
 (0)