From 98334f6a2d2030221975c457eb038008c76efdcb Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 5 Mar 2023 05:51:23 -0600 Subject: [PATCH] Don't walk the `tests/` directories in checks that always skip it `WalkBuilder` handles top-level paths differently than `fn walk` used to: it doesn't run the `skip` function to determine if it should be skipped, instead assuming the top-level function is always included. This is a reasonable assumption; adapt our code so it doesn't make pointless calls to `walk`. --- src/tools/tidy/src/edition.rs | 37 +++++++++++++------------------- src/tools/tidy/src/main.rs | 2 -- src/tools/tidy/src/unit_tests.rs | 1 - 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index ae8233aa9108..67d9c30a04ff 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -9,27 +9,20 @@ fn is_edition_2021(mut line: &str) -> bool { } pub fn check(path: &Path, bad: &mut bool) { - walk( - path, - |path| { - filter_dirs(path) - || (path.ends_with("tests") && path.join("COMPILER_TESTS.md").exists()) - }, - &mut |entry, contents| { - let file = entry.path(); - let filename = file.file_name().unwrap(); - if filename != "Cargo.toml" { - return; - } + walk(path, |path| filter_dirs(path), &mut |entry, contents| { + let file = entry.path(); + let filename = file.file_name().unwrap(); + if filename != "Cargo.toml" { + return; + } - let is_2021 = contents.lines().any(is_edition_2021); - if !is_2021 { - tidy_error!( - bad, - "{} doesn't have `edition = \"2021\"` on a separate line", - file.display() - ); - } - }, - ); + let is_2021 = contents.lines().any(is_edition_2021); + if !is_2021 { + tidy_error!( + bad, + "{} doesn't have `edition = \"2021\"` on a separate line", + file.display() + ); + } + }); } diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 505f9d724c8d..d98758ace4fc 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -91,7 +91,6 @@ fn main() { // Checks that need to be done for both the compiler and std libraries. check!(unit_tests, &src_path); - check!(unit_tests, &tests_path); check!(unit_tests, &compiler_path); check!(unit_tests, &library_path); @@ -107,7 +106,6 @@ fn main() { check!(edition, &src_path); check!(edition, &compiler_path); check!(edition, &library_path); - check!(edition, &tests_path); check!(alphabetical, &src_path); check!(alphabetical, &tests_path); diff --git a/src/tools/tidy/src/unit_tests.rs b/src/tools/tidy/src/unit_tests.rs index 24ab81587db1..3da200a8a931 100644 --- a/src/tools/tidy/src/unit_tests.rs +++ b/src/tools/tidy/src/unit_tests.rs @@ -24,7 +24,6 @@ pub fn check(root_path: &Path, bad: &mut bool) { let file_name = path.file_name().unwrap_or_default(); if path.is_dir() { filter_dirs(path) - || path.ends_with("tests") || path.ends_with("src/doc") || (file_name == "tests" || file_name == "benches") && !is_core(path) } else {