`unused_crate_dependencies` false positive for dev-dependencies on main crate
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Steps to reproduce:
cargo new mycrate
cd mycrate
cargo add --dev termtree
printf '[lints.rust]\nunused_crate_dependencies = "deny"\n' >> Cargo.toml
cargo build --all-targets
Result:
error: external crate `termtree` unused in `mycrate`: remove the dependency or add `use termtree as _;`
|
= note: requested on the command line with `-D unused-crate-dependencies`
error: could not compile `mycrate` (bin "mycrate" test) due to 1 previous error
dev-dependencies have a variety of uses, and should not be considered as potentially unused. I'd love to see unused dev-dependencies detected as well, but right now they produce false positives.
The reverse is also true: rustc will warn about unused non-dev dependencies when compiling tests.
Short-term, perhaps we could provide a way to easily disable this warning entirely for dev-dependencies, and for non-dev dependencies in targets such as tests.
Longer-term, perhaps rustc could feed information about potentially unused dependencies back to Cargo in its output, and Cargo could then aggregate the intersection of those dependencies that are completely unused.
Meanwhile, however, these false positives make it difficult to use unused_crate_dependencies in any project that has dev-dependencies or tests.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Cargo.toml lint configuration and cargo build --all-targets commands shown, focusing on unused_crate_dependencies behavior for dev-dependencies and test targets. Review the compiler/Cargo interaction involved; done means these dependency contexts no longer produce the reported false positives, with the intended scope agreed first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100