diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 45f4ef286..42c93cfd3 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1240,51 +1240,49 @@ impl<'cfg> Workspace<'cfg> { } } - let ms: Vec<_> = self - .members() - .filter_map(|member| { - let member_id = member.package_id(); - match self.current_opt() { - // The features passed on the command-line only apply to - // the "current" package (determined by the cwd). - Some(current) if member_id == current.package_id() => { + let ms: Vec<_> = self.members().filter_map(|member| { + let member_id = member.package_id(); + match self.current_opt() { + // The features passed on the command-line only apply to + // the "current" package (determined by the cwd). + Some(current) if member_id == current.package_id() => { + let feats = CliFeatures { + features: Rc::new(cwd_features.clone()), + all_features: cli_features.all_features, + uses_default_features: cli_features.uses_default_features, + }; + Some((member, feats)) + } + _ => { + // Ignore members that are not enabled on the command-line. + if specs.iter().any(|spec| spec.matches(member_id)) { + // -p for a workspace member that is not the "current" + // one. + // + // The odd behavior here is due to backwards + // compatibility. `--features` and + // `--no-default-features` used to only apply to the + // "current" package. As an extension, this allows + // member-name/feature-name to set member-specific + // features, which should be backwards-compatible. let feats = CliFeatures { - features: Rc::new(cwd_features.clone()), + features: Rc::new( + member_specific_features + .remove(member.name().as_str()) + .unwrap_or_default(), + ), + uses_default_features: true, all_features: cli_features.all_features, - uses_default_features: cli_features.uses_default_features, }; Some((member, feats)) - } - _ => { - // Ignore members that are not enabled on the command-line. - if specs.iter().any(|spec| spec.matches(member_id)) { - // -p for a workspace member that is not the "current" - // one. - // - // The odd behavior here is due to backwards - // compatibility. `--features` and - // `--no-default-features` used to only apply to the - // "current" package. As an extension, this allows - // member-name/feature-name to set member-specific - // features, which should be backwards-compatible. - let feats = CliFeatures { - features: Rc::new( - member_specific_features - .remove(member.name().as_str()) - .unwrap_or_default(), - ), - uses_default_features: true, - all_features: cli_features.all_features, - }; - Some((member, feats)) - } else { - // This member was not requested on the command-line, skip. - None - } + } else { + // This member was not requested on the command-line, skip. + None } } - }) - .collect(); + } + }) + .collect(); // If any member specific features were not removed while iterating over members // some features will be ignored.