rust-lang / rust-lang/rust

unused_crate_dependencies not working correctly with -Z build-std

Open
#122,105 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics L-unused_crate_dependencies T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the cargo clippy command in the issue and inspect domains/client/relayer/src/lib.rs, especially the unused_crate_dependencies lint. Trace why -Z build-std reports alloc, compiler_builtins, panic_unwind, proc_macro, and test as unused; done means the command no longer emits these false errors while the lint still detects genuinely unused dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.