rust-lang / rust-lang/rust-clippy
Lint using `next_back` when `last` is more appropriate
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
It makes sense to lint the use of next_back in cases where the iterator is not used beyond the call to next_back, suggesting to replace last instead. Additionally, implementations of Iterator::last that only delegate to next_back should be suggested to be removed.
This will likely need to be special cased to only do this for iterators which are known to optimise last into next_back through some sort of whitelist.
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
The issue names no files, tests, or entry points. Start by locating the existing iterator-related lints and the implementations of Iterator::last and next_back, then determine the whitelist needed to distinguish optimized cases. Done means the appropriate next_back calls and redundant last implementations are linted without false positives.
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
- 30/100