-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add the iter_last_slice lint
#15496
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
base: master
Are you sure you want to change the base?
Add the iter_last_slice lint
#15496
Conversation
|
No changes for 8ea1451 |
c59a6eb to
9ec4984
Compare
This lint triggers when calling `.iter().last()` on a slice or array and suggests using `.last()` directly. This is a modified version of the `iter_next_slice`. I could not figure out how to avoid code duplication though :/.
9ec4984 to
8ea1451
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some drive-by comments..
| iter_overeager_cloned::Op::LaterCloned, | ||
| false, | ||
| ); | ||
| double_ended_iterator_last::check(cx, expr, recv, call_span); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why repeat this check in two match arms? I think leaving it outside the match is fine..
|
|
||
| let _ = s.iter().last(); | ||
| //~^ iter_last_slice | ||
| // Should be replaced by s.last() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these comments could be left out -- the .fixed file already captures the intended output
| cx, | ||
| ITER_LAST_SLICE, | ||
| expr.span, | ||
| "using `.iter().last()` on a slice without end index", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "using `.iter().last()` on a slice without end index", | |
| "using `.iter().last()` on a slice without start index", |
|
☔ The latest upstream changes (possibly ebbbbeb) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@ada4a I don't have much energy to dedicate to this PR (and to open source in general) for health reasons. Things should go better in 2-3 weeks. If that's too long, you can close this PR and I will reopen a new one (with all the points you railed addressed) when I'm back :) |
Sorry to hear that, wishing you a swift recovery!
No need, it can wait for a bit:) |
Fixes #15487.
This lint triggers when calling
.iter().last()on a slice or array and suggests using.last()directly.This is a modified version of the
iter_next_slice. I could not figure out how to avoid code duplication though :/.changelog: Add
iter_last_slicelint