Skip to content

Commit 4623a71

Browse files
rukaielchukc
authored andcommitted
improve error reporting when feature not found in activated_features
1 parent ad074ab commit 4623a71

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
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.keys()
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.

tests/testsuite/artifact_dep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ fn artifact_dep_target_specified() {
15731573
.masquerade_as_nightly_cargo(&["bindeps"])
15741574
.with_stdout_data("")
15751575
.with_stderr_data(r#"...
1576-
[..]activated_features for invalid package: features did not find PackageId { name: "bindep", version: "0.0.0", source: "[..]" } NormalOrDev[..]
1576+
[..]did not find features for (PackageId { name: "bindep", version: "0.0.0", source: "[..]" }, NormalOrDev) within activated_features:[..]
15771577
...
15781578
"#)
15791579
.with_status(101)

0 commit comments

Comments
 (0)