From 3fdd84ab3ab664bcc6e56a3ff5853ce7945399e8 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 16 Nov 2023 13:25:49 +1100 Subject: [PATCH 1/3] Allow trailing commas in static suggestions --- src/tools/suggest-tests/src/static_suggestions.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/suggest-tests/src/static_suggestions.rs b/src/tools/suggest-tests/src/static_suggestions.rs index a84e78254f269..6e196e626a84e 100644 --- a/src/tools/suggest-tests/src/static_suggestions.rs +++ b/src/tools/suggest-tests/src/static_suggestions.rs @@ -2,7 +2,7 @@ use crate::{sug, Suggestion}; // FIXME: perhaps this could use `std::lazy` when it is stablizied macro_rules! static_suggestions { - ($( $glob:expr => [ $( $suggestion:expr ),* ] ),*) => { + ($( $glob:expr => [ $( $suggestion:expr ),* $(,)? ] ),* $(,)? ) => { pub(crate) const STATIC_SUGGESTIONS: ::once_cell::unsync::Lazy)>> = ::once_cell::unsync::Lazy::new(|| vec![ $( ($glob, vec![ $($suggestion),* ]) ),*]); } @@ -10,15 +10,15 @@ macro_rules! static_suggestions { static_suggestions! { "*.md" => [ - sug!("test", 0, ["linkchecker"]) + sug!("test", 0, ["linkchecker"]), ], "compiler/*" => [ sug!("check"), - sug!("test", 1, ["tests/ui", "tests/run-make"]) + sug!("test", 1, ["tests/ui", "tests/run-make"]), ], "src/librustdoc/*" => [ - sug!("test", 1, ["rustdoc"]) - ] + sug!("test", 1, ["rustdoc"]), + ], } From 925111c2eb85681697155edbaf694f6693427a69 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 16 Nov 2023 13:18:40 +1100 Subject: [PATCH 2/3] Support multiple globs in static suggestions --- src/tools/suggest-tests/src/lib.rs | 16 +++++++++------- .../suggest-tests/src/static_suggestions.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/tools/suggest-tests/src/lib.rs b/src/tools/suggest-tests/src/lib.rs index 44cd3c7f6a84d..1c1d9d0333ddb 100644 --- a/src/tools/suggest-tests/src/lib.rs +++ b/src/tools/suggest-tests/src/lib.rs @@ -33,13 +33,15 @@ pub fn get_suggestions>(modified_files: &[T]) -> Vec { let mut suggestions = Vec::new(); // static suggestions - for sug in STATIC_SUGGESTIONS.iter() { - let glob = Pattern::new(&sug.0).expect("Found invalid glob pattern!"); - - for file in modified_files { - if glob.matches(file.as_ref()) { - suggestions.extend_from_slice(&sug.1); - } + for (globs, sugs) in STATIC_SUGGESTIONS.iter() { + let globs = globs + .iter() + .map(|glob| Pattern::new(glob).expect("Found invalid glob pattern!")) + .collect::>(); + let matches_some_glob = |file: &str| globs.iter().any(|glob| glob.matches(file)); + + if modified_files.iter().map(AsRef::as_ref).any(matches_some_glob) { + suggestions.extend_from_slice(sugs); } } diff --git a/src/tools/suggest-tests/src/static_suggestions.rs b/src/tools/suggest-tests/src/static_suggestions.rs index 6e196e626a84e..1dc02de6ea4dc 100644 --- a/src/tools/suggest-tests/src/static_suggestions.rs +++ b/src/tools/suggest-tests/src/static_suggestions.rs @@ -2,23 +2,23 @@ use crate::{sug, Suggestion}; // FIXME: perhaps this could use `std::lazy` when it is stablizied macro_rules! static_suggestions { - ($( $glob:expr => [ $( $suggestion:expr ),* $(,)? ] ),* $(,)? ) => { - pub(crate) const STATIC_SUGGESTIONS: ::once_cell::unsync::Lazy)>> - = ::once_cell::unsync::Lazy::new(|| vec![ $( ($glob, vec![ $($suggestion),* ]) ),*]); + ($( [ $( $glob:expr ),* $(,)? ] => [ $( $suggestion:expr ),* $(,)? ] ),* $(,)? ) => { + pub(crate) const STATIC_SUGGESTIONS: ::once_cell::unsync::Lazy, Vec)>> + = ::once_cell::unsync::Lazy::new(|| vec![ $( (vec![ $($glob),* ], vec![ $($suggestion),* ]) ),*]); } } static_suggestions! { - "*.md" => [ + ["*.md"] => [ sug!("test", 0, ["linkchecker"]), ], - "compiler/*" => [ + ["compiler/*"] => [ sug!("check"), sug!("test", 1, ["tests/ui", "tests/run-make"]), ], - "src/librustdoc/*" => [ + ["src/librustdoc/*"] => [ sug!("test", 1, ["rustdoc"]), ], } From 05322162abf3cc5bb66848b37af82d6442486a48 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 16 Nov 2023 13:24:35 +1100 Subject: [PATCH 3/3] Add test suggestions for `mir-opt` and `coverage` --- src/tools/suggest-tests/src/static_suggestions.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tools/suggest-tests/src/static_suggestions.rs b/src/tools/suggest-tests/src/static_suggestions.rs index 1dc02de6ea4dc..fbd265ea42a2e 100644 --- a/src/tools/suggest-tests/src/static_suggestions.rs +++ b/src/tools/suggest-tests/src/static_suggestions.rs @@ -18,6 +18,17 @@ static_suggestions! { sug!("test", 1, ["tests/ui", "tests/run-make"]), ], + ["compiler/rustc_mir_transform/*"] => [ + sug!("test", 1, ["mir-opt"]), + ], + + [ + "compiler/rustc_mir_transform/src/coverage/*", + "compiler/rustc_codegen_llvm/src/coverageinfo/*", + ] => [ + sug!("test", 1, ["coverage"]), + ], + ["src/librustdoc/*"] => [ sug!("test", 1, ["rustdoc"]), ],