Skip to content

Commit 47735b1

Browse files
committed
Auto merge of #1714 - alexcrichton:default-feature-oscillating, r=huonw
There was previously a bug in resolve where turning off the default set of features would cause resolve to not correctly settle on the set of features activated for a package. If one dependency turned off all features, and then the next dependency to be activated only turned on the default feature, the default feature wouldn't actually end up getting activated. This commit alters the check to see if the package has been previously activated to more rigorously check to see if the 'default' feature is activated previously. If a dependency doesn't use the default feature, or if the package itself does not have the feature "default", then the package is considered activated, but otherwise it needs to go through another cycle of resolution.
2 parents ba47db2 + 0ba5a7a commit 47735b1

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,14 @@ fn flag_activated(cx: &mut Context,
234234
}
235235
Method::Everything => return false,
236236
};
237+
238+
let has_default_feature = summary.features().contains_key("default");
237239
match cx.resolve.features(id) {
238240
Some(prev) => {
239241
features.iter().all(|f| prev.contains(f)) &&
240-
(!use_default || prev.contains("default"))
242+
(!use_default || prev.contains("default") || !has_default_feature)
241243
}
242-
None => features.len() == 0,
244+
None => features.len() == 0 && (!use_default || !has_default_feature)
243245
}
244246
}
245247

tests/support/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl ProjectBuilder {
134134

135135
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
136136
let mut p = process(program).unwrap();
137-
p.cwd(&self.root()).env("HOME", &paths::home());
137+
p.cwd(&self.root())
138+
.env("HOME", &paths::home())
139+
.env_remove("CARGO_HOME");
138140
return p;
139141
}
140142

tests/test_cargo_features.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,49 @@ test!(no_rebuild_when_frobbing_default_feature {
695695
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
696696
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
697697
});
698+
699+
test!(unions_work_with_no_default_features {
700+
let p = project("foo")
701+
.file("Cargo.toml", r#"
702+
[package]
703+
name = "foo"
704+
version = "0.1.0"
705+
authors = []
706+
707+
[dependencies]
708+
a = { path = "a" }
709+
b = { path = "b" }
710+
"#)
711+
.file("src/lib.rs", r#"
712+
extern crate a;
713+
pub fn foo() { a::a(); }
714+
"#)
715+
.file("b/Cargo.toml", r#"
716+
[package]
717+
name = "b"
718+
version = "0.1.0"
719+
authors = []
720+
721+
[dependencies]
722+
a = { path = "../a", features = [], default-features = false }
723+
"#)
724+
.file("b/src/lib.rs", "")
725+
.file("a/Cargo.toml", r#"
726+
[package]
727+
name = "a"
728+
version = "0.1.0"
729+
authors = []
730+
731+
[features]
732+
default = ["f1"]
733+
f1 = []
734+
"#)
735+
.file("a/src/lib.rs", r#"
736+
#[cfg(feature = "f1")]
737+
pub fn a() {}
738+
"#);
739+
740+
assert_that(p.cargo_process("build"), execs().with_status(0));
741+
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
742+
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
743+
});

0 commit comments

Comments
 (0)