RS.CLIPPY.DOUBLE_ENDED_ITERATOR_LAST

Using `Iterator::last` on a `DoubleEndedIterator`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: double_ended_iterator_last. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for Iterator::last being called on a DoubleEndedIterator, which can be replaced with DoubleEndedIterator::next_back.

Why is this bad?

Iterator::last is implemented by consuming the iterator, which is unnecessary if the iterator is a DoubleEndedIterator. Since Rust traits do not allow specialization, Iterator::last cannot be optimized for DoubleEndedIterator.

Example

let last_arg = "echo hello world".split(\' \').last();

Use instead:

let last_arg = "echo hello world".split(\' \').next_back();