diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-26 22:11:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-26 22:11:29 +0200 |
| commit | e38fdda243c890bc8f4ce93eb82fd1bf750ebbe7 (patch) | |
| tree | a9654d285094708c102d3a980c6013c0d75bf612 /src/librustc_session | |
| parent | 0747f586ebada402e2b2d5cb14ab40d5f33518a6 (diff) | |
| parent | ffa493ab57fbb44f16efae2515abdde6876cc5c9 (diff) | |
Rollup merge of #72342 - jsgf:warn-unused-deps, r=petrochenkov
Warn about unused crate deps
Implements #57274 by adding -Wunused-crate-dependencies. This will warn about any `--extern` option on the command line which isn't referenced by the crate source either via `use` or `extern crate`.
Crates which are added for some side effect but are otherwise unreferenced - such as for symbols they define - the warning can be suppressed with `use somecrate as _;`.
If a crate has multiple aliases (eg using `foo = { package = "bar" }` in `Cargo.toml`), then it will warn about each unused alias.
This does not consider crate added by some other means than `--extern`, including the standard library. It also doesn't consider any crate without `add_prelude` set (though I'm not sure about this).
Unfortunately this probably [does not yet work well with Cargo](https://github.com/rust-lang/rust/issues/57274#issuecomment-624839355) as it will over-specify crates, causing spurious warnings. As a result, this lint is "allow" by default and must be explicitly enabled either via `#![warn(unused_crate_deps)]` or with `-Wunused-crate-deps`.
Diffstat (limited to 'src/librustc_session')
| -rw-r--r-- | src/librustc_session/lint/builtin.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index 40354172048..e55ddc26a94 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -72,6 +72,12 @@ declare_lint! { } declare_lint! { + pub UNUSED_CRATE_DEPENDENCIES, + Allow, + "crate dependencies that are never used" +} + +declare_lint! { pub UNUSED_QUALIFICATIONS, Allow, "detects unnecessarily qualified names" @@ -529,6 +535,7 @@ declare_lint_pass! { UNCONDITIONAL_PANIC, UNUSED_IMPORTS, UNUSED_EXTERN_CRATES, + UNUSED_CRATE_DEPENDENCIES, UNUSED_QUALIFICATIONS, UNKNOWN_LINTS, UNUSED_VARIABLES, |
