Skip to content

Commit 70a9883

Browse files
committed
Replace repeated zips with a dedicated StepExtra struct
1 parent 49205a1 commit 70a9883

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/bootstrap/src/core/builder/cli_paths.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,25 @@ impl From<PathBuf> for CLIStepPath {
8989
}
9090
}
9191

92+
/// Combines a `StepDescription` with its corresponding `ShouldRun`.
93+
struct StepExtra<'a> {
94+
desc: &'a StepDescription,
95+
should_run: ShouldRun<'a>,
96+
}
97+
9298
pub(crate) fn match_paths_to_steps_and_run(
9399
builder: &Builder<'_>,
94-
v: &[StepDescription],
100+
step_descs: &[StepDescription],
95101
paths: &[PathBuf],
96102
) {
97-
let should_runs = v
103+
// Obtain `ShouldRun` information for each step, so that we know which
104+
// paths to match it against.
105+
let steps = step_descs
98106
.iter()
99-
.map(|desc| (desc.should_run)(ShouldRun::new(builder, desc.kind)))
107+
.map(|desc| StepExtra {
108+
desc,
109+
should_run: (desc.should_run)(ShouldRun::new(builder, desc.kind)),
110+
})
100111
.collect::<Vec<_>>();
101112

102113
// FIXME(Zalathar): This particular check isn't related to path-to-step
@@ -110,12 +121,12 @@ pub(crate) fn match_paths_to_steps_and_run(
110121
}
111122

112123
// sanity checks on rules
113-
for (desc, should_run) in v.iter().zip(&should_runs) {
124+
for StepExtra { desc, should_run } in &steps {
114125
assert!(!should_run.paths.is_empty(), "{:?} should have at least one pathset", desc.name);
115126
}
116127

117128
if paths.is_empty() || builder.config.include_default_paths {
118-
for (desc, should_run) in v.iter().zip(&should_runs) {
129+
for StepExtra { desc, should_run } in &steps {
119130
if desc.default && should_run.is_really_default() {
120131
desc.maybe_run(builder, should_run.paths.iter().cloned().collect());
121132
}
@@ -159,7 +170,7 @@ pub(crate) fn match_paths_to_steps_and_run(
159170
// Handle all test suite paths.
160171
// (This is separate from the loop below to avoid having to handle multiple paths in `is_suite_path` somehow.)
161172
paths.retain(|path| {
162-
for (desc, should_run) in v.iter().zip(&should_runs) {
173+
for StepExtra { desc, should_run } in &steps {
163174
if let Some(suite) = should_run.is_suite_path(path) {
164175
desc.maybe_run(builder, vec![suite.clone()]);
165176
return false;
@@ -181,7 +192,7 @@ pub(crate) fn match_paths_to_steps_and_run(
181192
// the steps.
182193
let mut steps_to_run = vec![];
183194

184-
for (desc, should_run) in v.iter().zip(&should_runs) {
195+
for StepExtra { desc, should_run } in &steps {
185196
let pathsets = should_run.pathset_for_paths_removing_matches(&mut paths, desc.kind);
186197

187198
// This value is used for sorting the step execution order.

0 commit comments

Comments
 (0)