From 2352cbd1f9c2cd89bab004b7d2f0290b15f97420 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Mon, 6 Nov 2023 19:57:58 +0000 Subject: [PATCH 1/2] add a test --- tests/testsuite/update.rs | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 8a58e4c801c..8bbcf4b2e13 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -391,6 +391,59 @@ 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") + // This terrible error message was a regression in #12749 + .with_stderr( + "\ +[UPDATING] `[..]` index +thread 'main' panicked at src/cargo/util/semver_ext.rs:79:9: +cannot update_precise ~1.2 to 1.6.0 +[..] +", + ) + .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(); From 7997306a0b5989befb0ccd3a55f9eb66d8616d43 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Mon, 6 Nov 2023 19:57:58 +0000 Subject: [PATCH 2/2] restore error message --- src/cargo/util/semver_ext.rs | 6 ------ tests/testsuite/update.rs | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cargo/util/semver_ext.rs b/src/cargo/util/semver_ext.rs index 5ad61f5787f..7863ba15d1f 100644 --- a/src/cargo/util/semver_ext.rs +++ b/src/cargo/util/semver_ext.rs @@ -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 { diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 8bbcf4b2e13..e636435b00e 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -417,13 +417,14 @@ fn update_precise_mismatched() { // `1.6.0` does not match `"~1.2"` p.cargo("update serde:1.2 --precise 1.6.0") - // This terrible error message was a regression in #12749 .with_stderr( "\ [UPDATING] `[..]` index -thread 'main' panicked at src/cargo/util/semver_ext.rs:79:9: -cannot update_precise ~1.2 to 1.6.0 -[..] +[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) @@ -434,11 +435,11 @@ cannot update_precise ~1.2 to 1.6.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)` - ", +[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();