Skip to content

Commit 1b902d4

Browse files
committed
Auto merge of #1873 - alexcrichton:fix-transitive-activation, r=brson
When activating the feature `foo/bar` you're actually activating both the feature `foo` and the `bar` feature of the relevant package. Cargo previously forgot to activate the `foo` feature, and this commit fixes that up. Closes #1871
2 parents 553b363 + e2e1751 commit 1b902d4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Diff for: src/cargo/core/resolver/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ fn build_features(s: &Summary, method: Method)
556556
match parts.next() {
557557
Some(feat) => {
558558
let package = feat_or_package;
559+
used.insert(package.to_string());
559560
deps.entry(package.to_string())
560561
.or_insert(Vec::new())
561562
.push(feat.to_string());

Diff for: tests/test_cargo_features.rs

+38
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,41 @@ test!(optional_and_dev_dep {
769769
{compiling} test v0.1.0 ([..])
770770
", compiling = COMPILING)));
771771
});
772+
773+
test!(activating_feature_activates_dep {
774+
let p = project("foo")
775+
.file("Cargo.toml", r#"
776+
[package]
777+
name = "test"
778+
version = "0.1.0"
779+
authors = []
780+
781+
[dependencies]
782+
foo = { path = "foo", optional = true }
783+
784+
[features]
785+
a = ["foo/a"]
786+
"#)
787+
.file("src/lib.rs", "
788+
extern crate foo;
789+
pub fn bar() {
790+
foo::bar();
791+
}
792+
")
793+
.file("foo/Cargo.toml", r#"
794+
[package]
795+
name = "foo"
796+
version = "0.1.0"
797+
authors = []
798+
799+
[features]
800+
a = []
801+
"#)
802+
.file("foo/src/lib.rs", r#"
803+
#[cfg(feature = "a")]
804+
pub fn bar() {}
805+
"#);
806+
807+
assert_that(p.cargo_process("build").arg("--features").arg("a").arg("-v"),
808+
execs().with_status(0));
809+
});

0 commit comments

Comments
 (0)