rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.75k stars 2.42k forks source link

`cargo tree -d` incorrectly shows duplicate workspace dependency with resolver = "2" #14732

Open dima74 opened 1 week ago

dima74 commented 1 week ago

Problem

Given workspace with three crates: Image

Where crate1 and crate2 use dep identically:

[dependencies]
dep = { path = "../dep", default-features = false }

Then cargo tree -d reports duplicate dep dependency

Steps

[dependencies] dep = { path = "../dep", default-features = false }


* `crates/crate2/Cargo.toml`:
```toml
[package]
name = "crate2"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
dep = { path = "../dep", default-features = false }

[features] default = ["foo"] foo = []


* `cargo tree -d`:

dep v0.0.0 (.../crates/dep) └── crate2 v0.0.0 (proc-macro) (.../crates/crate2)

dep v0.0.0 (.../crates/dep) └── crate1 v0.0.0 (.../crates/crate1)



### Possible Solution(s)

_No response_

### Notes

All of this should be true for the issue to reproduce:
* `resolver = "2"`
* Either `crate1` or `crate2` is a proc macro
* `dep` has non-empty `default-features`

### Version

cargo 1.83.0-nightly (c1fa840a8 2024-08-29)
release: 1.83.0-nightly
commit-hash: c1fa840a85eca53818895901a53fae34247448b2
commit-date: 2024-08-29
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Arch Linux Rolling Release [64-bit]
ehuss commented 1 week ago

Thanks for the report! This is working as intended. The crates are duplicated because they are being built with different features. You can view the differences with the -f "{p} {f}" flag.