Skip to content

Commit ba8cfe1

Browse files
committed
Refactor checking loop to iterator.collect()
1 parent 2115265 commit ba8cfe1

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed

src/cargo/core/workspace.rs

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,64 +1237,67 @@ impl<'cfg> Workspace<'cfg> {
12371237
}
12381238
}
12391239

1240-
let mut result = Vec::new();
1241-
for member in self.members() {
1242-
let member_id = member.package_id();
1243-
match self.current_opt() {
1244-
// The features passed on the command-line only apply to
1245-
// the "current" package (determined by the cwd).
1246-
Some(current) if member_id == current.package_id() => {
1247-
let feats = CliFeatures {
1248-
features: Rc::new(cwd_features.clone()),
1249-
all_features: cli_features.all_features,
1250-
uses_default_features: cli_features.uses_default_features,
1251-
};
1252-
1253-
result.push((member, feats))
1254-
}
1255-
_ => {
1256-
// Ignore members that are not enabled on the command-line.
1257-
if specs.iter().any(|spec| spec.matches(member_id)) {
1258-
// -p for a workspace member that is not the "current" one.
1259-
//
1260-
// The odd behavior here is due to backwards
1261-
// compatibility. `--features` and
1262-
// `--no-default-features` used to only apply to the
1263-
// "current" package. As an extension, this allows
1264-
// member-name/feature-name to set member-specific
1265-
// features, which should be backwards-compatible.
1240+
let result: Vec<_> = self
1241+
.members()
1242+
.filter_map(|member| {
1243+
let member_id = member.package_id();
1244+
match self.current_opt() {
1245+
// The features passed on the command-line only apply to
1246+
// the "current" package (determined by the cwd).
1247+
Some(current) if member_id == current.package_id() => {
12661248
let feats = CliFeatures {
1267-
features: Rc::new(
1268-
member_specific_features
1269-
.remove(member.name().as_str())
1270-
.unwrap_or_default()
1271-
.into_iter()
1272-
.map(|feature| match feature {
1273-
// I think weak can be ignored here.
1274-
// With `--features member?/feat -p member`, the ? doesn't
1275-
// really mean anything (either the member is built or it isn't).
1276-
FeatureValue::DepFeature {
1277-
dep_name: _,
1278-
dep_feature,
1279-
dep_prefix: false,
1280-
weak: _,
1281-
} => FeatureValue::new(dep_feature),
1282-
// Member specific features by definition contain only `FeatureValue::DepFeature`
1283-
_ => unreachable!(),
1284-
})
1285-
.collect(),
1286-
),
1287-
uses_default_features: true,
1249+
features: Rc::new(cwd_features.clone()),
12881250
all_features: cli_features.all_features,
1251+
uses_default_features: cli_features.uses_default_features,
12891252
};
12901253

1291-
result.push((member, feats))
1292-
} else {
1293-
// This member was not requested on the command-line, skip.
1254+
Some((member, feats))
1255+
}
1256+
_ => {
1257+
// Ignore members that are not enabled on the command-line.
1258+
if specs.iter().any(|spec| spec.matches(member_id)) {
1259+
// -p for a workspace member that is not the "current" one.
1260+
//
1261+
// The odd behavior here is due to backwards
1262+
// compatibility. `--features` and
1263+
// `--no-default-features` used to only apply to the
1264+
// "current" package. As an extension, this allows
1265+
// member-name/feature-name to set member-specific
1266+
// features, which should be backwards-compatible.
1267+
let feats = CliFeatures {
1268+
features: Rc::new(
1269+
member_specific_features
1270+
.remove(member.name().as_str())
1271+
.unwrap_or_default()
1272+
.into_iter()
1273+
.map(|feature| match feature {
1274+
// I think weak can be ignored here.
1275+
// With `--features member?/feat -p member`, the ? doesn't
1276+
// really mean anything (either the member is built or it isn't).
1277+
FeatureValue::DepFeature {
1278+
dep_name: _,
1279+
dep_feature,
1280+
dep_prefix: false,
1281+
weak: _,
1282+
} => FeatureValue::new(dep_feature),
1283+
// Member specific features by definition contain only `FeatureValue::DepFeature`
1284+
_ => unreachable!(),
1285+
})
1286+
.collect(),
1287+
),
1288+
uses_default_features: true,
1289+
all_features: cli_features.all_features,
1290+
};
1291+
1292+
Some((member, feats))
1293+
} else {
1294+
// This member was not requested on the command-line, skip.
1295+
None
1296+
}
12941297
}
12951298
}
1296-
}
1297-
}
1299+
})
1300+
.collect();
12981301

12991302
// If any member specific features were not removed while iterating over members
13001303
if !member_specific_features.is_empty() {

0 commit comments

Comments
 (0)