You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: ignore implicit std dependencies in unused-crate-dependencies lint (#16677)
fixes [152561](rust-lang/rust#152561)
### What does this PR try to solve?
Cargo explicitly passes standard library crates (core, alloc, etc.) as
extern dependencies when using `-Zbuild-std`, which causes "erroneous"
warnings because these crates are not listed in the user's Cargo.toml.
### The working
This was initially issued on the `rust` repo, for which i filed a PR,
using `noprelude` to exclude linting, but it was correctly pointed out
that this was not the correct approach.
Following
[Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/unused_crate_dependencies.20with.20cargo.20-Zbuild-std/with/575423436)
discussions, I added a `nounused` flag to the `UnitDeps` struct which is
similar in working to the `noprelude` flag.
`--extern nounused:foo` already exists as an unstable compiler option.
### How to test and review this PR?
1. To demonstrate that the implicitly injected crates no longer trigger
linting warnings, use this test command: `rustup run nightly cargo test
build_std_does_not_warn_about_implicit_std_deps`.
2. Verify that `core`, `alloc`, `compiler_builtins` do not throw unused
warnings.
**Note:** this makes build-std stabilization blocked on
rust-lang/rust#98400 which is blocked on
rust-lang/rust#98405 (which I think is already
a dependence of build-std)
---
Currently, `nounused` is emitted only for implicitly injected standard
library dependencies when using `-Zbuild-std`.
If Cargo ever gains support for explicit builtin dependencies declared
by users, it may be desirable to revisit whether `nounused` should apply
in those cases. This PR does not change behavior for explicit
dependencies.
0 commit comments