Skip to content

Commit 6f33738

Browse files
committed
Fix cargo clean -p crashing with -Zfeatures.
1 parent 6154645 commit 6f33738

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,37 @@ impl RequestedFeatures {
151151
impl ResolvedFeatures {
152152
/// Returns the list of features that are enabled for the given package.
153153
pub fn activated_features(&self, pkg_id: PackageId, is_build: bool) -> Vec<InternedString> {
154+
self.activated_features_int(pkg_id, is_build, true)
155+
}
156+
157+
/// Variant of `activated_features` that returns an empty Vec if this is
158+
/// not a valid pkg_id/is_build combination. Used by `cargo clean` which
159+
/// doesn't know the exact set.
160+
pub fn activated_features_unverified(
161+
&self,
162+
pkg_id: PackageId,
163+
is_build: bool,
164+
) -> Vec<InternedString> {
165+
self.activated_features_int(pkg_id, is_build, false)
166+
}
167+
168+
fn activated_features_int(
169+
&self,
170+
pkg_id: PackageId,
171+
is_build: bool,
172+
verify: bool,
173+
) -> Vec<InternedString> {
154174
if let Some(legacy) = &self.legacy {
155175
legacy.get(&pkg_id).map_or_else(Vec::new, |v| v.clone())
156176
} else {
157177
let is_build = self.opts.decouple_build_deps && is_build;
158-
// TODO: Remove panic, return empty set.
159-
let fs = self
160-
.activated_features
161-
.get(&(pkg_id, is_build))
162-
.unwrap_or_else(|| panic!("features did not find {:?} {:?}", pkg_id, is_build));
163-
fs.iter().cloned().collect()
178+
if let Some(fs) = self.activated_features.get(&(pkg_id, is_build)) {
179+
fs.iter().cloned().collect()
180+
} else if verify {
181+
panic!("features did not find {:?} {:?}", pkg_id, is_build)
182+
} else {
183+
Vec::new()
184+
}
164185
}
165186
}
166187
}
@@ -436,9 +457,8 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
436457
.dep_platform_activated(dep, CompileKind::Host);
437458
}
438459
// Not a build dependency, and not for a build script, so must be Target.
439-
return self
440-
.target_data
441-
.dep_platform_activated(dep, self.requested_target);
460+
self.target_data
461+
.dep_platform_activated(dep, self.requested_target)
442462
};
443463
self.resolve
444464
.deps(pkg_id)

src/cargo/ops/cargo_clean.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
116116
*mode,
117117
)
118118
};
119-
let features = features
120-
.activated_features(pkg.package_id(), unit_for.is_for_build_dep());
119+
// Use unverified here since this is being more
120+
// exhaustive than what is actually needed.
121+
let features = features.activated_features_unverified(
122+
pkg.package_id(),
123+
unit_for.is_for_build_dep(),
124+
);
121125
units.push(bcx.units.intern(
122126
pkg, target, profile, *kind, *mode, features, /*is_std*/ false,
123127
));

0 commit comments

Comments
 (0)