rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.45k stars 12.73k forks source link

Unhelpful error message when specifying incompatible dependencies #132850

Closed msrd0 closed 2 days ago

msrd0 commented 2 days ago

Code

**`Cargo.toml`**

[package]
name = "foo"
version = "0.1.0"
publish = false
edition = "2021"

[dependencies]
pulldown-cmark = { version = "0.12.2", default-features = false }

[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
pulldown-cmark = { version = "0.11", default-features = false, features = ["simd"] }

**`src/lib.rs`**

use pulldown_cmark;

Current output

Updating crates.io index
     Locking 1 package to latest compatible version
      Adding pulldown-cmark v0.11.3 (latest: v0.12.2)
  Downloaded pulldown-cmark v0.11.3
  Downloaded 1 crate (145.3 KB) in 0.09s
   Compiling pulldown-cmark v0.11.3
   Compiling pulldown-cmark v0.12.2
   Compiling foo v0.1.0 (/tmp/foo)
error[E0464]: multiple candidates for `rmeta` dependency `pulldown_cmark` found
 --> src/lib.rs:1:5
  |
1 | use pulldown_cmark;
  |     ^^^^^^^^^^^^^^
  |
  = note: candidate #1: /tmp/foo/target/debug/deps/libpulldown_cmark-fad4c8962c375cb9.rmeta
  = note: candidate #2: /tmp/foo/target/debug/deps/libpulldown_cmark-385191dabac2676c.rmeta

For more information about this error, try `rustc --explain E0464`.
error: could not compile `foo` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

Desired output

error[Exxxx]: multiple candidates for dependency `pulldown_cmark` found
 --> Cargo.toml:11:1
   |
11 | pulldown-cmark = { version = "0.11", default-features = false, features = ["simd"] }
   |
note: previous dependency declared here
 --> Cargo.toml:8:1
   |
 8 | pulldown-cmark = { version = "0.12.2", default-features = false }
   |

Rationale and extra context

From the above error message, I get the feeling that something happened within the rust compiler / package manager / whatever that placed something wrong in the target folder. However, it wasn't a problem with the contents of the target folder but with my dependencies. Therefore, the error message should point there.

Other cases

Rust Version

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Anything else?

No response

ehuss commented 2 days ago

Thanks for the report! I believe this is a duplicate of https://github.com/rust-lang/cargo/issues/8032, so closing in favor of that. Cargo should not be allowing multiple dependencies with the same name.