diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index ed00428630e..5ab42b30f38 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -234,9 +234,10 @@ impl<'a> PackageRegistry<'a> { // sure to lock to precisely the given package id. // // 2. We have a lock entry for this dependency, but it's from a - // different source than what's listed. In this case we must - // discard the locked version because the listed source must - // have changed. + // different source than what's listed, or the version + // requirement has changed. In this case we must discard the + // locked version because the dependency needs to be + // re-resolved. // // 3. We don't have a lock entry for this dependency, in which // case it was likely an optional dependency which wasn't @@ -244,7 +245,7 @@ impl<'a> PackageRegistry<'a> { Some(&(_, ref deps)) => { match deps.iter().find(|d| d.get_name() == dep.get_name()) { Some(lock) => { - if lock.get_source_id() == dep.get_source_id() { + if dep.matches_id(lock) { dep.lock_to(lock) } else { dep diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 366453c7ac4..8bb32cbc224 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -499,3 +499,62 @@ test!(bad_license_file { .with_stderr("\ the license file `foo` does not exist")); }) + +test!(updating_a_dep { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.a] + path = "a" + "#) + .file("src/main.rs", "fn main() {}") + .file("a/Cargo.toml", r#" + [project] + name = "a" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "*" + "#) + .file("a/src/lib.rs", ""); + p.build(); + + r::mock_pkg("bar", "0.0.1", &[]); + + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0).with_stdout(format!("\ +{updating} registry `[..]` +{downloading} bar v0.0.1 (registry file://[..]) +{compiling} bar v0.0.1 (registry file://[..]) +{compiling} a v0.0.1 ({dir}) +{compiling} foo v0.0.1 ({dir}) +", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING, + dir = p.url()).as_slice())); + + File::create(&p.root().join("a/Cargo.toml")).write_str(r#" + [project] + name = "a" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + "#).unwrap(); + r::mock_pkg("bar", "0.1.0", &[]); + + println!("second"); + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0).with_stdout(format!("\ +{updating} registry `[..]` +{downloading} bar v0.1.0 (registry file://[..]) +{compiling} bar v0.1.0 (registry file://[..]) +{compiling} a v0.0.1 ({dir}) +{compiling} foo v0.0.1 ({dir}) +", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING, + dir = p.url()).as_slice())); +})