You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
clarfonthey opened this issue
Jun 10, 2017
· 1 comment
Labels
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types
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.
The text was updated successfully, but these errors were encountered:
mcarton
added
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
A-lint
Area: New lints
T-middle
Type: Probably requires verifiying types
labels
Jun 10, 2017
I think I would rather go the other way around, warning about last when iterator implements DoubleEndedIterator. The problem with last is that it doesn't require DoubleEndedIterator to be implemented which means that in general case it's going to be slow, and while this can be dealt with manual implementation of that method, most iterators in standard library don't bother to do so. For those that do bother, I don't expect any particular difference between next_back and last even when the iterator is to be immediately dropped.
Jakobeha
added a commit
to Jakobeha/enquote
that referenced
this issue
May 3, 2024
idk if it makes a difference optimized, but the former theoretically traverses the entire string, while the latter doesn't. Semantically they're the exact same. Also see rust-lang/rust-clippy#1822, it doesn't seem like this is well-known.
Jakobeha
added a commit
to Jakobeha/enquote
that referenced
this issue
May 3, 2024
Idk if it makes a difference optimized, but the former theoretically traverses the entire string, while the latter doesn't. Semantically they're the exact same. Also see rust-lang/rust-clippy#1822, it doesn't seem like this is well-known.
)
I [recently realized that `.last()` might not call `next_back()` when it
is
available](https://qsantos.fr/2025/01/01/rust-gotcha-last-on-doubleendediterator/).
Although the implementor could make sure to implement `last()` to do so,
this is not what will happen by default. As a result, I think it is
useful to add a lint to promote using `.next_back()` over `.last()` on
`DoubleEndedIterator`.
If this is merged, we might want to close #1822.
changelog: [`double_ended_iterator_last`]: Add lint for calling
`Iterator::last()` on `DoubleEndedIterator`
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types
It makes sense to lint the use of
next_back
in cases where the iterator is not used beyond the call tonext_back
, suggesting to replacelast
instead. Additionally, implementations ofIterator::last
that only delegate tonext_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
intonext_back
through some sort of whitelist.The text was updated successfully, but these errors were encountered: