diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 15bb496dbc2..b895fe3b6a6 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -167,6 +167,13 @@ pub(super) fn activation_error( msg.push_str("` does have feature `"); msg.push_str(closest); msg.push_str("`\n"); + } else if !latest.features().is_empty() { + let mut features: Vec<_> = + latest.features().keys().map(|f| f.as_str()).collect(); + features.sort(); + msg.push_str(" available features: "); + msg.push_str(&features.join(", ")); + msg.push_str("\n"); } // p == parent so the full path is redundant. } diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 0f1f89c5fa5..956ed09f67f 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -282,6 +282,57 @@ package `foo` depends on `bar` with feature `bar` but `bar` does not have that f package `bar` does have feature `baz` +failed to select a version for `bar` which could resolve this conflict + +"#]]) + .run(); +} + +#[cargo_test] +fn dependency_activates_feature_with_no_close_match() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + + [dependencies.bar] + path = "bar" + features = ["serde"] + "#, + ) + .file("src/main.rs", "") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + edition = "2015" + + [features] + json = [] + tls = [] + cookies = [] +"#, + ) + .file("bar/src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] failed to select a version for `bar`. + ... required by package `foo v0.0.1 ([ROOT]/foo)` +versions that meet the requirements `*` are: 0.0.1 + +package `foo` depends on `bar` with feature `serde` but `bar` does not have that feature. + available features: cookies, json, tls + + failed to select a version for `bar` which could resolve this conflict "#]])