rust-clippy
rust-clippy copied to clipboard
Rewrite `lifetimes` lint pass
Based on rust-lang/rust-clippy#14702
This should generally be a perf improvement. The old implementation allocated a lot of things and then did multiple passes over the data. This only does a single pass allocating significantly less. It also bails out earlier in most cases.
Some behaviour changes:
- An ICE was fixed with debug assertions where removing multiple lifetime arguments could create overlapping spans. These spans are now merged into a single span.
- The lint message has been changed in the first commit. Adding all the lifetime names to the message is pointless when the lint spans already highlights those.
- The main lint span now no longer points to all uses. The suggestion already makes it clear what needs to change, no need to make the main lint span messy. It was especially bad when the signature was split over multiple lines.
- The help message was change to be a little more direct about what gets removed, but I'm not really attached either way.
- The lifetime in
dyn Trait + 'ais now elided when possible instead of completely bailing out of the lint. - Lifetimes appearing in various spots no longer completely bails out. Instead this leaves just those lifetimes alone.
- There is a regression for
<'a, T: 'a>where'ais only used for the type outlives constraint. Theses lifetimes can be removed, but I'd rather handle that at the same time as handling outlives constraints on lifetimes.
changelog: [elidable_lifetime_names]: Lint when dyn Trait + 'a can be elided.
changelog: [needless_lifetimes] [elidable_lifetime_names]: Lint more cases when only some lifetimes can be elided.