False positive `unused_lifetime`
Open
Nobody has claimed this yet.
A-diagnostics
C-bug
D-invalid-suggestion
L-unused_lifetimes
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![warn(unused_lifetimes)]
struct S;
pub fn repro()
where
for<'a> S: Clone,
{
}
pub fn main() {}
=>
warning: lifetime parameter `'a` never used
--> src/main.rs:6:13
|
6 | for<'a> S: Clone,
| ----^^-- help: elide the unused lifetime
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(unused_lifetimes)]
suggested code (cargo fix)
#![warn(unused_lifetimes)]
struct S;
pub fn repro()
where
S: Clone,
{
}
pub fn main() {}
does not compile:
error[E0277]: the trait bound `S: Clone` is not satisfied
--> src/main.rs:6:9
|
6 | S: Clone,
| ^^^^^^^^ the trait `Clone` is not implemented for `S`
|
= help: see issue #48214
help: consider annotating `S` with `#[derive(Clone)]`
|
2 + #[derive(Clone)]
3 | struct S;
|
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
2 + #![feature(trivial_bounds)]
|
For more information about this error, try `rustc --explain E0277`.
error: could not compile `f` (bin "f") due to 1 previous error
rustc 1.89.0-nightly (1bbd62e54 2025-05-29)
binary: rustc
commit-hash: 1bbd62e547ba5cc08ccb44c27def3d33195d2dd5
commit-date: 2025-05-29
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
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
Start with the src/main.rs reproducer and compare the unused_lifetimes warning with the cargo fix suggestion. Trace why removing the lifetime changes the trait-bound behavior, then verify that the warning and suggested code no longer produce an invalid fix while preserving the intended lint behavior.
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
- Clearly specified
- Newbie friendliness
- 42/100