about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-11-16 13:18:40 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-11-16 14:02:51 +1100
commit925111c2eb85681697155edbaf694f6693427a69 (patch)
tree366695f41853d4244557cd7f6643168fe8b0f18d
parent3fdd84ab3ab664bcc6e56a3ff5853ce7945399e8 (diff)
downloadrust-925111c2eb85681697155edbaf694f6693427a69.tar.gz
rust-925111c2eb85681697155edbaf694f6693427a69.zip
Support multiple globs in static suggestions
-rw-r--r--src/tools/suggest-tests/src/lib.rs16
-rw-r--r--src/tools/suggest-tests/src/static_suggestions.rs12
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 44cd3c7f6a8..1c1d9d0333d 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<T: AsRef<str>>(modified_files: &[T]) -> Vec<Suggestion> {
     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::<Vec<_>>();
+        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 6e196e626a8..1dc02de6ea4 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<Vec<(&'static str, Vec<Suggestion>)>>
-            = ::once_cell::unsync::Lazy::new(|| vec![ $( ($glob, vec![ $($suggestion),* ]) ),*]);
+    ($( [ $( $glob:expr ),* $(,)? ] => [ $( $suggestion:expr ),* $(,)? ] ),* $(,)? ) => {
+        pub(crate) const STATIC_SUGGESTIONS: ::once_cell::unsync::Lazy<Vec<(Vec<&'static str>, Vec<Suggestion>)>>
+            = ::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"]),
     ],
 }