about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-28 08:50:59 +0000
committerbors <bors@rust-lang.org>2025-07-28 08:50:59 +0000
commit65b6cdb6a6d33987b9d642a4882283c71fbe3957 (patch)
tree47ab86eab570baf05d3cc2bf04275fc78460cfec /src
parentd242a8bd5a73f633ba1ec5aacf19acf35a3c747d (diff)
parentc462895a6f0b463ff0c1c1db2a3a654d7e5976c7 (diff)
downloadrust-65b6cdb6a6d33987b9d642a4882283c71fbe3957.tar.gz
rust-65b6cdb6a6d33987b9d642a4882283c71fbe3957.zip
Auto merge of #144562 - matthiaskrgr:rollup-mlvn7qo, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#144072 (update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs)
 - rust-lang/rust#144151 (`tests/ui/issues/`: The Issues Strike Back [1/N])
 - rust-lang/rust#144300 (Clippy fixes for miropt-test-tools)
 - rust-lang/rust#144399 (Add a ratchet for moving all standard library tests to separate packages)
 - rust-lang/rust#144472 (str: Mark unstable `round_char_boundary` feature functions as const)
 - rust-lang/rust#144503 (Various refactors to the codegen coordinator code (part 3))
 - rust-lang/rust#144530 (coverage: Infer `instances_used` from `pgo_func_name_var_map`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/tools/miropt-test-tools/Cargo.toml2
-rw-r--r--src/tools/miropt-test-tools/src/lib.rs23
-rw-r--r--src/tools/tidy/src/main.rs6
-rw-r--r--src/tools/tidy/src/unit_tests.rs87
4 files changed, 70 insertions, 48 deletions
diff --git a/src/tools/miropt-test-tools/Cargo.toml b/src/tools/miropt-test-tools/Cargo.toml
index 09b4c7d16dc..3eb5020968d 100644
--- a/src/tools/miropt-test-tools/Cargo.toml
+++ b/src/tools/miropt-test-tools/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "miropt-test-tools"
 version = "0.1.0"
-edition = "2021"
+edition = "2024"
 
 [dependencies]
diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs
index 41b53d2ad0e..10769c9c8ab 100644
--- a/src/tools/miropt-test-tools/src/lib.rs
+++ b/src/tools/miropt-test-tools/src/lib.rs
@@ -34,7 +34,7 @@ fn output_file_suffix(testfile: &Path, bit_width: u32, panic_strategy: PanicStra
 
     let mut suffix = String::new();
     if each_bit_width {
-        suffix.push_str(&format!(".{}bit", bit_width));
+        suffix.push_str(&format!(".{bit_width}bit"));
     }
     if each_panic_strategy {
         match panic_strategy {
@@ -51,7 +51,7 @@ pub fn files_for_miropt_test(
     panic_strategy: PanicStrategy,
 ) -> MiroptTest {
     let mut out = Vec::new();
-    let test_file_contents = fs::read_to_string(&testfile).unwrap();
+    let test_file_contents = fs::read_to_string(testfile).unwrap();
 
     let test_dir = testfile.parent().unwrap();
     let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
@@ -76,10 +76,10 @@ pub fn files_for_miropt_test(
 
             if test_name.ends_with(".diff") {
                 let trimmed = test_name.trim_end_matches(".diff");
-                passes.push(trimmed.split('.').last().unwrap().to_owned());
-                let test_against = format!("{}.after.mir", trimmed);
-                from_file = format!("{}.before.mir", trimmed);
-                expected_file = format!("{}{}.diff", trimmed, suffix);
+                passes.push(trimmed.split('.').next_back().unwrap().to_owned());
+                let test_against = format!("{trimmed}.after.mir");
+                from_file = format!("{trimmed}.before.mir");
+                expected_file = format!("{trimmed}{suffix}.diff");
                 assert!(test_names.next().is_none(), "two mir pass names specified for MIR diff");
                 to_file = Some(test_against);
             } else if let Some(first_pass) = test_names.next() {
@@ -92,10 +92,9 @@ pub fn files_for_miropt_test(
                 }
                 assert!(test_names.next().is_none(), "three mir pass names specified for MIR diff");
 
-                expected_file =
-                    format!("{}{}.{}-{}.diff", test_name, suffix, first_pass, second_pass);
-                let second_file = format!("{}.{}.mir", test_name, second_pass);
-                from_file = format!("{}.{}.mir", test_name, first_pass);
+                expected_file = format!("{test_name}{suffix}.{first_pass}-{second_pass}.diff");
+                let second_file = format!("{test_name}.{second_pass}.mir");
+                from_file = format!("{test_name}.{first_pass}.mir");
                 to_file = Some(second_file);
             } else {
                 // Allow-list for file extensions that can be produced by MIR dumps.
@@ -112,7 +111,7 @@ pub fn files_for_miropt_test(
                     )
                 }
 
-                expected_file = format!("{}{}.{}", test_name_wo_ext, suffix, test_name_ext);
+                expected_file = format!("{test_name_wo_ext}{suffix}.{test_name_ext}");
                 from_file = test_name.to_string();
                 assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
                 to_file = None;
@@ -123,7 +122,7 @@ pub fn files_for_miropt_test(
                 );
             };
             if !expected_file.starts_with(&test_crate) {
-                expected_file = format!("{}.{}", test_crate, expected_file);
+                expected_file = format!("{test_crate}.{expected_file}");
             }
             let expected_file = test_dir.join(expected_file);
 
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index 794b0addee3..cd2567ddb64 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -128,9 +128,9 @@ fn main() {
         check!(pal, &library_path);
 
         // Checks that need to be done for both the compiler and std libraries.
-        check!(unit_tests, &src_path);
-        check!(unit_tests, &compiler_path);
-        check!(unit_tests, &library_path);
+        check!(unit_tests, &src_path, false);
+        check!(unit_tests, &compiler_path, false);
+        check!(unit_tests, &library_path, true);
 
         if bins::check_filesystem_support(&[&root_path], &output_directory) {
             check!(bins, &root_path);
diff --git a/src/tools/tidy/src/unit_tests.rs b/src/tools/tidy/src/unit_tests.rs
index df9146b5147..3d14a467319 100644
--- a/src/tools/tidy/src/unit_tests.rs
+++ b/src/tools/tidy/src/unit_tests.rs
@@ -1,44 +1,60 @@
 //! Tidy check to ensure `#[test]` and `#[bench]` are not used directly inside
-//! `core` or `alloc`.
+//! of the standard library.
 //!
 //! `core` and `alloc` cannot be tested directly due to duplicating lang items.
 //! All tests and benchmarks must be written externally in
 //! `{coretests,alloctests}/{tests,benches}`.
 //!
-//! Outside of `core` and `alloc`, tests and benchmarks should be outlined into
-//! separate files named `tests.rs` or `benches.rs`, or directories named
+//! Outside of the standard library, tests and benchmarks should be outlined
+//! into separate files named `tests.rs` or `benches.rs`, or directories named
 //! `tests` or `benches` unconfigured during normal build.
 
 use std::path::Path;
 
 use crate::walk::{filter_dirs, walk};
 
-pub fn check(root_path: &Path, bad: &mut bool) {
-    let core = root_path.join("core");
-    let core_copy = core.clone();
-    let is_core = move |path: &Path| path.starts_with(&core);
-    let alloc = root_path.join("alloc");
-    let alloc_copy = alloc.clone();
-    let is_alloc = move |path: &Path| path.starts_with(&alloc);
-
+pub fn check(root_path: &Path, stdlib: bool, bad: &mut bool) {
     let skip = move |path: &Path, is_dir| {
         let file_name = path.file_name().unwrap_or_default();
+
+        // Skip excluded directories and non-rust files
         if is_dir {
-            filter_dirs(path)
-                || path.ends_with("src/doc")
-                || (file_name == "tests" || file_name == "benches")
-                    && !is_core(path)
-                    && !is_alloc(path)
+            if filter_dirs(path) || path.ends_with("src/doc") {
+                return true;
+            }
         } else {
             let extension = path.extension().unwrap_or_default();
-            extension != "rs"
-                || (file_name == "tests.rs" || file_name == "benches.rs")
-                    && !is_core(path)
-                    && !is_alloc(path)
-                // Tests which use non-public internals and, as such, need to
-                // have the types in the same crate as the tests themselves. See
-                // the comment in alloctests/lib.rs.
-                || path.ends_with("library/alloc/src/collections/btree/borrow/tests.rs")
+            if extension != "rs" {
+                return true;
+            }
+        }
+
+        // Tests in a separate package are always allowed
+        if is_dir && file_name != "tests" && file_name.as_encoded_bytes().ends_with(b"tests") {
+            return true;
+        }
+
+        if !stdlib {
+            // Outside of the standard library tests may also be in separate files in the same crate
+            if is_dir {
+                if file_name == "tests" || file_name == "benches" {
+                    return true;
+                }
+            } else {
+                if file_name == "tests.rs" || file_name == "benches.rs" {
+                    return true;
+                }
+            }
+        }
+
+        if is_dir {
+            // FIXME remove those exceptions once no longer necessary
+            file_name == "std_detect" || file_name == "std" || file_name == "test"
+        } else {
+            // Tests which use non-public internals and, as such, need to
+            // have the types in the same crate as the tests themselves. See
+            // the comment in alloctests/lib.rs.
+            path.ends_with("library/alloc/src/collections/btree/borrow/tests.rs")
                 || path.ends_with("library/alloc/src/collections/btree/map/tests.rs")
                 || path.ends_with("library/alloc/src/collections/btree/node/tests.rs")
                 || path.ends_with("library/alloc/src/collections/btree/set/tests.rs")
@@ -50,22 +66,29 @@ pub fn check(root_path: &Path, bad: &mut bool) {
 
     walk(root_path, skip, &mut |entry, contents| {
         let path = entry.path();
-        let is_core = path.starts_with(&core_copy);
-        let is_alloc = path.starts_with(&alloc_copy);
+        let package = path
+            .strip_prefix(root_path)
+            .unwrap()
+            .components()
+            .next()
+            .unwrap()
+            .as_os_str()
+            .to_str()
+            .unwrap();
         for (i, line) in contents.lines().enumerate() {
             let line = line.trim();
             let is_test = || line.contains("#[test]") && !line.contains("`#[test]");
             let is_bench = || line.contains("#[bench]") && !line.contains("`#[bench]");
-            let manual_skip = line.contains("//tidy:skip");
-            if !line.starts_with("//") && (is_test() || is_bench()) && !manual_skip {
-                let explanation = if is_core {
-                    "`core` unit tests and benchmarks must be placed into `coretests`"
-                } else if is_alloc {
-                    "`alloc` unit tests and benchmarks must be placed into `alloctests`"
+            if !line.starts_with("//") && (is_test() || is_bench()) {
+                let explanation = if stdlib {
+                    format!(
+                        "`{package}` unit tests and benchmarks must be placed into `{package}tests`"
+                    )
                 } else {
                     "unit tests and benchmarks must be placed into \
                          separate files or directories named \
                          `tests.rs`, `benches.rs`, `tests` or `benches`"
+                        .to_owned()
                 };
                 let name = if is_test() { "test" } else { "bench" };
                 tidy_error!(