Skip to content

suggestion: .rev().next() #10274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bojanserafimov opened this issue Feb 1, 2023 · 1 comment · Fixed by #10769
Closed

suggestion: .rev().next() #10274

bojanserafimov opened this issue Feb 1, 2023 · 1 comment · Fixed by #10769
Labels
A-lint Area: New lints

Comments

@bojanserafimov
Copy link

bojanserafimov commented Feb 1, 2023

What it does

Suggest .next_back() insteaad of .rev().next() when that's equivalent.

Lint Name

iter_rev_next

Category

pedantic

Advantage

People will point it out at code review anyway. Might as well spare them some typing

Drawbacks

I haven't thought about edge cases where applying the suggestion would not be correct

Example

foo.iter().rev().next()

Could be written as:

foo.iter().next_back()
@bojanserafimov bojanserafimov added the A-lint Area: New lints label Feb 1, 2023
@KisaragiEffective
Copy link
Contributor

This is applicable when the type of foo.iter() is DoubleEndedIterator: both rev and next_back requires it as a bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants