Skip to content

Unkind error message failing patch non-existing package with a prerelease version package #12315

@loloicci

Description

@loloicci

Problem

Trying to patch a stable version package (0.1.0) with prerelease version one (0.1.1-prerelease) fails with an unkind error message if there are no other matching repositories. For example,

root's Cargo.toml:

[package]
name = "cargo-mybin"
version = "0.1.0"
edition = "2021"

[dependencies]
cargo-mylib = "0.1.0"

[patch.crates-io]
cargo-mylib = { git = "https://github.com/loloicci/cargo-mylib.git" }

cargo-mylib's Cargo.toml

[package]
name = "cargo-mylib"
version = "0.1.1-prerelease"
edition = "2021"

cargo update in this cargo-mybin fails with

$ cargo update
    Updating git repository `https://github.com/loloicci/cargo-mylib.git`
    Updating crates.io index
error: no matching package named `cargo-mylib` found
location searched: registry `crates-io`
required by package `cargo-mybin v0.1.0 (/.../cargo-mybin)`

This message says wrong information that no matching package was found. This is because

let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);
does not match prerelease version.

Steps

  1. clone https://github.com/loloicci/cargo-mybin
  2. execute cargo update on it

Possible Solution(s)

use OptVersionReq::Any instead of semver::VersionReq::parse("*").unwrap() in

let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);
.

Notes

No response

Version

$ cargo version --verbose
cargo 1.71.0-nightly (09276c703 2023-05-16)
release: 1.71.0-nightly
commit-hash: 09276c703a473ab33daaeb94917232e80eefd628
commit-date: 2023-05-16
host: x86_64-apple-darwin
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 7.64.1 (sys:0.4.61+curl-8.0.1 system ssl:(SecureTransport) LibreSSL/2.8.3)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Mac OS 10.15.7 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dependency-resolutionArea: dependency resolution and the resolverA-diagnosticsArea: Error and warning messages generated by Cargo itself.A-semverArea: semver specifications, version matching, etc.C-bugCategory: bugE-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions