Skip to content

Commit b0f2c6b

Browse files
rukaielchukc
authored andcommitted
refactor resolver features
1 parent cf781da commit b0f2c6b

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,32 @@ impl ResolvedFeatures {
319319
pkg_id: PackageId,
320320
features_for: FeaturesFor,
321321
) -> Vec<InternedString> {
322-
self.activated_features_int(pkg_id, features_for)
323-
.expect("activated_features for invalid package")
322+
let fk = features_for.apply_opts(&self.opts);
323+
let key = (pkg_id, fk);
324+
if let Some(fs) = self.activated_features.get(&key) {
325+
fs.iter().cloned().collect()
326+
} else {
327+
panic!(
328+
"did not find features for {key:?} within activated_features:\n{:#?}",
329+
self.activated_features
330+
)
331+
}
332+
}
333+
334+
/// Variant of `activated_features` that returns `None` if this is
335+
/// not a valid pkg_id/is_build combination. Used in places which do
336+
/// not know which packages are activated (like `cargo clean`).
337+
pub fn activated_features_unverified(
338+
&self,
339+
pkg_id: PackageId,
340+
features_for: FeaturesFor,
341+
) -> Option<Vec<InternedString>> {
342+
let fk = features_for.apply_opts(&self.opts);
343+
if let Some(fs) = self.activated_features.get(&(pkg_id, fk)) {
344+
Some(fs.iter().cloned().collect())
345+
} else {
346+
None
347+
}
324348
}
325349

326350
/// Returns if the given dependency should be included.
@@ -340,30 +364,6 @@ impl ResolvedFeatures {
340364
.unwrap_or(false)
341365
}
342366

343-
/// Variant of `activated_features` that returns `None` if this is
344-
/// not a valid pkg_id/is_build combination. Used in places which do
345-
/// not know which packages are activated (like `cargo clean`).
346-
pub fn activated_features_unverified(
347-
&self,
348-
pkg_id: PackageId,
349-
features_for: FeaturesFor,
350-
) -> Option<Vec<InternedString>> {
351-
self.activated_features_int(pkg_id, features_for).ok()
352-
}
353-
354-
fn activated_features_int(
355-
&self,
356-
pkg_id: PackageId,
357-
features_for: FeaturesFor,
358-
) -> CargoResult<Vec<InternedString>> {
359-
let fk = features_for.apply_opts(&self.opts);
360-
if let Some(fs) = self.activated_features.get(&(pkg_id, fk)) {
361-
Ok(fs.iter().cloned().collect())
362-
} else {
363-
bail!("features did not find {:?} {:?}", pkg_id, fk)
364-
}
365-
}
366-
367367
/// Compares the result against the original resolver behavior.
368368
///
369369
/// Used by `cargo fix --edition` to display any differences.

0 commit comments

Comments
 (0)