Skip to content

Commit 887ee6c

Browse files
committed
Fix bug with new feature resolver and required-features.
1 parent bda5051 commit 887ee6c

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl ResolvedFeatures {
194194
}
195195

196196
/// Variant of `activated_features` that returns an empty Vec if this is
197-
/// not a valid pkg_id/is_build combination. Used by `cargo clean` which
198-
/// doesn't know the exact set.
197+
/// not a valid pkg_id/is_build combination. Used in places which do
198+
/// not know which packages are activated (like `cargo clean`).
199199
pub fn activated_features_unverified(
200200
&self,
201201
pkg_id: PackageId,

src/cargo/ops/cargo_compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,8 @@ fn resolve_all_features(
956956
} else {
957957
FeaturesFor::NormalOrDev
958958
};
959-
for feature in resolved_features.activated_features(dep_id, features_for) {
960-
features.insert(dep.name_in_toml().to_string() + "/" + &feature);
959+
for feature in resolved_features.activated_features_unverified(dep_id, features_for) {
960+
features.insert(format!("{}/{}", dep.name_in_toml(), feature));
961961
}
962962
}
963963
}

tests/testsuite/features2.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for the new feature resolver.
22
3-
use cargo_test_support::project;
43
use cargo_test_support::registry::{Dependency, Package};
4+
use cargo_test_support::{basic_manifest, project};
55

66
#[cargo_test]
77
fn inactivate_targets() {
@@ -893,3 +893,41 @@ fn disabled_shared_build_dep() {
893893
.with_stdout("hello from somedep")
894894
.run();
895895
}
896+
897+
#[cargo_test]
898+
fn required_features_inactive_dep() {
899+
// required-features with an inactivated dep.
900+
let p = project()
901+
.file(
902+
"Cargo.toml",
903+
r#"
904+
[package]
905+
name = "foo"
906+
version = "0.1.0"
907+
908+
[target.'cfg(whatever)'.dependencies]
909+
bar = {path="bar"}
910+
911+
[[bin]]
912+
name = "foo"
913+
required-features = ["feat1"]
914+
915+
[features]
916+
feat1 = []
917+
"#,
918+
)
919+
.file("src/main.rs", "fn main() {}")
920+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
921+
.file("bar/src/lib.rs", "")
922+
.build();
923+
924+
p.cargo("check -Zfeatures=itarget")
925+
.masquerade_as_nightly_cargo()
926+
.with_stderr("[FINISHED] [..]")
927+
.run();
928+
929+
p.cargo("check -Zfeatures=itarget --features=feat1")
930+
.masquerade_as_nightly_cargo()
931+
.with_stderr("[CHECKING] foo[..]\n[FINISHED] [..]")
932+
.run();
933+
}

0 commit comments

Comments
 (0)