rust-lang/rust-clippy

New lint: `while let Some(&x) = slice.iter().next()` is infinite loop

Open

#4554 opened on Sep 19, 2019

View on GitHub
 (12 comments) (0 reactions) (1 assignee)Rust (10,406 stars) (1,391 forks)batch import
A-lintL-correctnessL-suggestiongood first issue

Description

This code is an infinite loop: (Do not run this in playpen)

fn main() {
    let a = [1, 2, 3];
    while let Some(&x) = a.iter().next() {
        println!("{:?}", x);
    }
}

Contributor guide