false positive `unused-extern-crates`
Open
Nobody has claimed this yet.
A-lints
C-bug
D-invalid-suggestion
L-false-positive
L-unused_extern_crates
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Using the following flags
--force-warn unused-extern-crates
this code:
// No error, panic handler is supplied by libstd linked though the empty library.
//@ check-pass
//@ aux-build: cfg_false_lib.rs
#![no_std]
extern crate proc_macro;
fn main() {
panic!()
}
caused the following diagnostics:
Checking _5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40 v0.1.0 (/tmp/icemaker_global_tempdir.ZzRBF4urpxex/icemaker_clippyfix_tempdir.aeQgi7GJI5WY/_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40)
warning: unused extern crate
--> src/main.rs:8:1
|
8 | extern crate proc_macro;
| ^^^^^^^^^^^^^^^^^^^^^^^^ unused
|
= note: requested on the command line with `--force-warn unused-extern-crates`
help: remove the unused `extern crate`
|
8 - extern crate proc_macro;
|
warning: `_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40` (bin "_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40") generated 1 warning (run `cargo clippy --fix --bin "_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40" -p _5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s
However after applying these diagnostics, the resulting code:
// No error, panic handler is supplied by libstd linked though the empty library.
//@ check-pass
//@ aux-build: cfg_false_lib.rs
#![no_std]
fn main() {
panic!()
}
no longer compiled:
Checking _5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40 v0.1.0 (/tmp/icemaker_global_tempdir.ZzRBF4urpxex/icemaker_clippyfix_tempdir.aeQgi7GJI5WY/_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40)
error: `#[panic_handler]` function required, but not found
error: unwinding panics are not supported without std
|
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
error: could not compile `_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40` (bin "_5ba66f8e62a4839c0ab39d6e4a771d7ada6b5b40") due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Version:
rustc 1.93.0-nightly (a8664a153 2025-10-26)
binary: rustc
commit-hash: a8664a1534913ccff491937ec2dc7ec5d973c2bd
commit-date: 2025-10-26
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3
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 supplied no_std example with --force-warn unused-extern-crates, then compare the diagnostics before and after removing extern crate proc_macro. Trace how this lint handles required linkage for the panic handler, and consider the issue done when the required crate is not falsely reported as unused and the example still compiles.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100