Skip to content

Commit

Permalink
Auto merge of #12923 - Eh2406:bug_12920, r=epage
Browse files Browse the repository at this point in the history
Bug 12920

Fix for #12920, a regression introduced in #12749.

This also as a test case for an existing Terrible error message.
  • Loading branch information
bors committed Nov 6, 2023
2 parents a9f6393 + 7997306 commit f095603
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/cargo/util/semver_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ impl OptVersionReq {
}

pub fn update_precise(&mut self, version: &Version) {
assert!(
self.matches(version),
"cannot update_precise {} to {}",
self,
version
);
use OptVersionReq::*;
let version = version.clone();
*self = match self {
Expand Down
54 changes: 54 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,60 @@ fn update_precise() {
.run();
}

#[cargo_test]
fn update_precise_mismatched() {
Package::new("serde", "1.2.0").publish();
Package::new("serde", "1.2.1").publish();
Package::new("serde", "1.6.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
serde = "~1.2"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check").run();

// `1.6.0` does not match `"~1.2"`
p.cargo("update serde:1.2 --precise 1.6.0")
.with_stderr(
"\
[UPDATING] `[..]` index
[ERROR] failed to select a version for the requirement `serde = \"~1.2\"`
candidate versions found which didn't match: 1.6.0
location searched: `[..]` index (which is replacing registry `crates-io`)
required by package `bar v0.0.1 ([..]/foo)`
perhaps a crate was updated and forgotten to be re-vendored?
",
)
.with_status(101)
.run();

// `1.9.0` does not exist
p.cargo("update serde:1.2 --precise 1.9.0")
// This terrible error message has been the same for a long time. A fix is more than welcome!
.with_stderr(
"\
[UPDATING] `[..]` index
[ERROR] no matching package named `serde` found
location searched: registry `crates-io`
required by package `bar v0.0.1 ([..]/foo)`
",
)
.with_status(101)
.run();
}

#[cargo_test]
fn update_precise_build_metadata() {
Package::new("serde", "0.0.1+first").publish();
Expand Down

0 comments on commit f095603

Please sign in to comment.