rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.3k stars 12.72k forks source link

unused_crate_dependencies not working correctly with -Z build-std #122105

Open nazar-pc opened 8 months ago

nazar-pc commented 8 months ago

Code

git clone https://github.com/subspace/subspace
cd domains/client/relayer
cargo clippy --all-targets -Z build-std --target x86_64-unknown-linux-gnu

Current output

error: external crate `alloc` unused in `domain_client_message_relayer`: remove the dependency or add `use alloc as _;`
  |
note: the lint level is defined here
 --> domains/client/relayer/src/lib.rs:2:9
  |
2 | #![deny(unused_crate_dependencies)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^

error: external crate `compiler_builtins` unused in `domain_client_message_relayer`: remove the dependency or add `use compiler_builtins as _;`

error: external crate `panic_unwind` unused in `domain_client_message_relayer`: remove the dependency or add `use panic_unwind as _;`

error: external crate `proc_macro` unused in `domain_client_message_relayer`: remove the dependency or add `use proc_macro as _;`

error: external crate `test` unused in `domain_client_message_relayer`: remove the dependency or add `use test as _;`

error: could not compile `domain-client-message-relayer` (lib test) due to 3 previous errors

Desired output

There is no error unless -Z build-std is used, which is confusing

Rationale and extra context

No response

Other cases

No response

Rust Version

Tested two versions with the same result:

rustc 1.78.0-nightly (c475e2303 2024-02-28)
binary: rustc
commit-hash: c475e2303b551d726307c646181e0677af1e0069
commit-date: 2024-02-28
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

rustc 1.78.0-nightly (b6d2d841b 2024-03-05)
binary: rustc
commit-hash: b6d2d841bcf4b77343b159f134c7d39c2dd4ceaa
commit-date: 2024-03-05
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

I do not see code mentioned in diagnostic in the crate, which adds to confusion.

superatomic commented 7 months ago

I can reproduce the same behavior on x86_64-apple-darwin. As a workaround, these messages can be ignored with RUSTFLAGS='-Aunused-crate-dependencies'.

Edit: Nevermind, I just had lints.rust.unused_crate_dependencies = "warn" set in my Cargo.toml file. Removing this line fixes the issue.