Skip to content

Fix overriding mixing with default features #3843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,23 @@ fn activate(cx: &mut Context,
candidate.summary.package_id().clone());
}

if cx.flag_activated(&candidate.summary, method) {
return Ok(None);
}
let activated = cx.flag_activated(&candidate.summary, method);

let candidate = match candidate.replace {
Some(replace) => {
cx.resolve_replacements.insert(candidate.summary.package_id().clone(),
replace.package_id().clone());
if cx.flag_activated(&replace, method) {
if cx.flag_activated(&replace, method) && activated {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this && activated. Can it cause the same replacement to be activated twice? Is it bad?

If I remove && activated, the tests pass just as well. So we either don't need it, or don't have some test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, we can move perhaps all ifs after replacement:

let candidate = match candidate.replace {
    Some(replace) => {
        cx.resolve_replacements.insert(candidate.summary.package_id().clone(),
                                       replace.package_id().clone());
        trace!("replacing {} with {}", candidate.summary.package_id(),
                replace.package_id());
        replace
    }
    None => candidate.summary,
};

if cx.flag_activated(&candidate, method) {
    return Ok(None)
}
trace!("activating {}", candidate.package_id());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like moving if forward won't work because during replacement we need to activate both the original and the replacement.

return Ok(None);
}
trace!("activating {} (replacing {})", replace.package_id(),
candidate.summary.package_id());
replace
}
None => {
if activated {
return Ok(None)
}
trace!("activating {}", candidate.summary.package_id());
candidate.summary
}
Expand Down
58 changes: 58 additions & 0 deletions tests/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,3 +1104,61 @@ warning: path override for crate `foo` has altered the original list of
dependencies; the dependency on `bar` was either added or\
"));
}

#[test]
fn override_with_default_feature() {
Package::new("another", "0.1.0").publish();
Package::new("another", "0.1.1")
.dep("bar", "0.1")
.publish();
Package::new("bar", "0.1.0").publish();

let p = project("local")
.file("Cargo.toml", r#"
[package]
name = "local"
version = "0.0.1"
authors = []

[dependencies]
bar = { path = "bar", default-features = false }
another = "0.1"
another2 = { path = "another2" }

[replace]
'bar:0.1.0' = { path = "bar" }
"#)
.file("src/main.rs", r#"
extern crate bar;

fn main() {
bar::bar();
}
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.1.0"
authors = []

[features]
default = []
"#)
.file("bar/src/lib.rs", r#"
#[cfg(feature = "default")]
pub fn bar() {}
"#)
.file("another2/Cargo.toml", r#"
[package]
name = "another2"
version = "0.1.0"
authors = []

[dependencies]
bar = { version = "0.1", default-features = false }
"#)
.file("another2/src/lib.rs", "");

assert_that(p.cargo_process("run"),
execs().with_status(0));
}