rust-lang / rust-lang/rust-clippy
[feature request] Auto-fix for `extra_unused_lifetimes`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
extra_unused_lifetimes doesn't have an auto-fix for the unused lifetimes it flags, but it'd be nice if it did.
fn unused_lt<'a>(x: u8) {}
could become
fn unused_lt<>(x: u8) {}
which I've seen my editor change to
fn unused_lt(x: u8) {}
on save.
I've thought about widening the range of the lint so it changes
fn unused_lt<'a>(x: u8) {}
to
fn unused_lt(x: u8) {}
but that could become messy in the case with
fn unused_lt<'a, 'b, 'c, 'd>(x: u8) {}
so I think it's fine to just have the auto-fix remove the unused lifetime and have a formatter remove any stray <>.
Edge Case
I've looked into this, and there's an edge case with
trait _Foo {
fn hey();
}
impl<'a, T: ?Sized> _Foo for &mut T {
fn hey() {}
}
since just removing 'a' results in
trait _Foo {
fn hey();
}
impl<, T: ?Sized> _Foo for &mut T {
fn hey() {}
}
and an error.
Version
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
Additional Labels
@rustbot label +
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 by locating the extra_unused_lifetimes lint implementation and its existing autofix tests. Check the single- and multiple-lifetime examples, including the impl<'a, T: ?Sized> edge case, and consider the work complete when the autofix removes unused lifetimes without producing invalid syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100