Skip to content

Don't warn about duplicates when a dependency is listed per target - #343

Merged
est31 merged 1 commit into
est31:masterfrom
b84330808:quiet-target-specific-duplicate-warning
Oct 22, 2026
Merged

est31 merged 1 commit into
est31:masterfrom
b84330808:quiet-target-specific-duplicate-warning

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Fixes #192

When a crate lists the same package more than once under the same name, for example

[target.'cfg(unix)'.dependencies]
if_chain = "1.0.0"

[target.'cfg(not(unix))'.dependencies]
if_chain = "1.0.0"

cargo-udeps prints warning: duplicate package mentioned in toml if_chain v1.0.3. if_chain. Both entries map the package to the same name, so nothing gets lost and the warning is just noise. Now it only warns when the names in the toml are different.

To test it I let the test runner hand back what was written to stderr (run_with_stderr; run behaves as before) and added tests/target-specific-dep.rs. It fails on master with the warning above and passes with this change. The rest of the test suite still passes.

One thing to note: cargo itself already rejects the same package listed under different names (apart from - vs _), so after this the warning rarely fires. I kept it rather than removing it, but I'm happy to drop it entirely if you prefer.

I used Claude Code to write this change.

A package that is listed several times under the same name, e.g. once
under `[target.'cfg(unix)'.dependencies]` and once under
`[target.'cfg(not(unix))'.dependencies]`, made cargo-udeps print
"duplicate package mentioned in toml". Nothing is lost in that case, so
only warn when the names in the toml differ.

The test runner can now return what was written to stderr, so the
regression test can check that the warning is gone.

Fixes #192

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@est31 est31 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@est31
est31 merged commit 354ce23 into est31:master Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive warning on duplicate dependency

2 participants