cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Unclear error message when workspace dep cannot be inherited in patch

Open 0xPoe opened this issue 2 years ago • 2 comments

Problem

Unclear error message when workspace dep cannot be inherited in patch. See also https://github.com/rust-lang/cargo/pull/12001#discussion_r1171995318

Steps

  1. Try cannot_inherit_in_patch unit test.
#[cargo_test]
fn cannot_inherit_in_patch() {
    Package::new("bar", "0.1.0").publish();

    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [workspace]
            members = []

            [workspace.dependencies]
            bar = { path = "bar" }

            [package]
            name = "foo"
            version = "0.2.0"

            [patch.crates-io]
            bar.workspace = true

            [dependencies]
            bar = "0.1.0"

        "#,
        )
        .file("src/main.rs", "fn main() {}")
        .build();

    p.cargo("check")
        .with_status(101)
        .with_stderr(
            "\
[WARNING] [CWD]/Cargo.toml: unused manifest key: patch.crates-io.bar.workspace
[WARNING] [CWD]/Cargo.toml: dependency (bar) specified without providing a local path, Git repository, version, \
or workspace dependency to use. \
This will be considered an error in future versions
[UPDATING] `dummy-registry` index
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`

Caused by:
  patch for `bar` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
",
        )
        .run();
}
  1. See the warnings and errors.

Possible Solution(s)

Give a clear error message to say Cargo can not inherit a workspace dep in patch.

Notes

No response

Version

cargo version --verbose
cargo 1.69.0 (6e9a83356 2023-04-12)
release: 1.69.0
commit-hash: 6e9a83356b70586d4b77613a6b33f9ea067b9cdf
commit-date: 2023-04-12
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.2.1 [64-bit]

0xPoe avatar Apr 25 '23 01:04 0xPoe

From https://github.com/rust-lang/cargo/issues/9885#issuecomment-919476834,

If we try again in the future, we will likely try to use the future-incompatible warning system which can report potential breaking in dependencies ahead of time.

Though we need to design the system in Cargo first. Or we can rely on -Zlints to have fine-grain control of Cargo's warnings.

weihanglo avatar Jun 02 '23 12:06 weihanglo

The error message was changed in #13775 to

[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
  dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use

See the tests cannot_inherit_in_patch and error_workspace_dependency_looked_for_workspace_itself

epage avatar May 21 '25 15:05 epage