RS.CLIPPY.MANUAL_WHILE_LET_SOME

Checking for emptiness of a `Vec` in the loop condition and popping an element in the body

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

What it does

Looks for loops that check for emptiness of a Vec in the condition and pop an element in the body as a separate operation.

Why is this bad?

Such loops can be written in a more idiomatic way by using a while-let loop and directly pattern matching on the return value of Vec::pop().

Example

let mut numbers = vec![1, 2, 3, 4, 5];
while !numbers.is_empty() {
    let number = numbers.pop().unwrap();
    // use `number`
}

Use instead:

let mut numbers = vec![1, 2, 3, 4, 5];
while let Some(number) = numbers.pop() {
    // use `number`
}