Skip to content

Commit f095603

Browse files
committed
Auto merge of #12923 - Eh2406:bug_12920, r=epage
Bug 12920 Fix for #12920, a regression introduced in #12749. This also as a test case for an existing Terrible error message.
2 parents a9f6393 + 7997306 commit f095603

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/cargo/util/semver_ext.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ impl OptVersionReq {
7676
}
7777

7878
pub fn update_precise(&mut self, version: &Version) {
79-
assert!(
80-
self.matches(version),
81-
"cannot update_precise {} to {}",
82-
self,
83-
version
84-
);
8579
use OptVersionReq::*;
8680
let version = version.clone();
8781
*self = match self {

tests/testsuite/update.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,60 @@ fn update_precise() {
391391
.run();
392392
}
393393

394+
#[cargo_test]
395+
fn update_precise_mismatched() {
396+
Package::new("serde", "1.2.0").publish();
397+
Package::new("serde", "1.2.1").publish();
398+
Package::new("serde", "1.6.0").publish();
399+
400+
let p = project()
401+
.file(
402+
"Cargo.toml",
403+
r#"
404+
[package]
405+
name = "bar"
406+
version = "0.0.1"
407+
authors = []
408+
409+
[dependencies]
410+
serde = "~1.2"
411+
"#,
412+
)
413+
.file("src/lib.rs", "")
414+
.build();
415+
416+
p.cargo("check").run();
417+
418+
// `1.6.0` does not match `"~1.2"`
419+
p.cargo("update serde:1.2 --precise 1.6.0")
420+
.with_stderr(
421+
"\
422+
[UPDATING] `[..]` index
423+
[ERROR] failed to select a version for the requirement `serde = \"~1.2\"`
424+
candidate versions found which didn't match: 1.6.0
425+
location searched: `[..]` index (which is replacing registry `crates-io`)
426+
required by package `bar v0.0.1 ([..]/foo)`
427+
perhaps a crate was updated and forgotten to be re-vendored?
428+
",
429+
)
430+
.with_status(101)
431+
.run();
432+
433+
// `1.9.0` does not exist
434+
p.cargo("update serde:1.2 --precise 1.9.0")
435+
// This terrible error message has been the same for a long time. A fix is more than welcome!
436+
.with_stderr(
437+
"\
438+
[UPDATING] `[..]` index
439+
[ERROR] no matching package named `serde` found
440+
location searched: registry `crates-io`
441+
required by package `bar v0.0.1 ([..]/foo)`
442+
",
443+
)
444+
.with_status(101)
445+
.run();
446+
}
447+
394448
#[cargo_test]
395449
fn update_precise_build_metadata() {
396450
Package::new("serde", "0.0.1+first").publish();

0 commit comments

Comments
 (0)