Skip to content

Commit e8ea0cd

Browse files
committed
Replace repeated zips with a dedicated StepExtra struct
1 parent 6965b47 commit e8ea0cd

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ 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
98-
.iter()
99-
.map(|desc| (desc.should_run)(ShouldRun::new(builder, desc.kind)))
100-
.collect::<Vec<_>>();
101-
102103
if builder.download_rustc() && (builder.kind == Kind::Dist || builder.kind == Kind::Install) {
103104
eprintln!(
104105
"ERROR: '{}' subcommand is incompatible with `rust.download-rustc`.",
@@ -107,13 +108,23 @@ pub(crate) fn match_paths_to_steps_and_run(
107108
crate::exit!(1);
108109
}
109110

111+
// Obtain `ShouldRun` information for each step, so that we know which
112+
// paths to match it against.
113+
let steps = step_descs
114+
.iter()
115+
.map(|desc| StepExtra {
116+
desc,
117+
should_run: (desc.should_run)(ShouldRun::new(builder, desc.kind)),
118+
})
119+
.collect::<Vec<_>>();
120+
110121
// sanity checks on rules
111-
for (desc, should_run) in v.iter().zip(&should_runs) {
122+
for StepExtra { desc, should_run } in &steps {
112123
assert!(!should_run.paths.is_empty(), "{:?} should have at least one pathset", desc.name);
113124
}
114125

115126
if paths.is_empty() || builder.config.include_default_paths {
116-
for (desc, should_run) in v.iter().zip(&should_runs) {
127+
for StepExtra { desc, should_run } in &steps {
117128
if desc.default && should_run.is_really_default() {
118129
desc.maybe_run(builder, should_run.paths.iter().cloned().collect());
119130
}
@@ -157,7 +168,7 @@ pub(crate) fn match_paths_to_steps_and_run(
157168
// Handle all test suite paths.
158169
// (This is separate from the loop below to avoid having to handle multiple paths in `is_suite_path` somehow.)
159170
paths.retain(|path| {
160-
for (desc, should_run) in v.iter().zip(&should_runs) {
171+
for StepExtra { desc, should_run } in &steps {
161172
if let Some(suite) = should_run.is_suite_path(path) {
162173
desc.maybe_run(builder, vec![suite.clone()]);
163174
return false;
@@ -179,7 +190,7 @@ pub(crate) fn match_paths_to_steps_and_run(
179190
// the steps.
180191
let mut steps_to_run = vec![];
181192

182-
for (desc, should_run) in v.iter().zip(&should_runs) {
193+
for StepExtra { desc, should_run } in &steps {
183194
let pathsets = should_run.pathset_for_paths_removing_matches(&mut paths, desc.kind);
184195

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

0 commit comments

Comments
 (0)