Skip to content

Wrong suggestion with while_let_loop #675

@mcarton

Description

@mcarton

Encountered something like that in the wild:

    loop {
        let (e, l) = match s.split_whitespace().next() {
            Some(word) => (word.is_empty(), word.len()),
            None => break
        };

        let _ = (e, l);
    }

produces:

foo.rs:46:5: 53:6 error: this loop could be written as a `while let` loop
foo.rs:46     loop {
foo.rs:47         let (e, l) = match s.split_whitespace().next() {
foo.rs:48             Some(word) => (word.is_empty(), word.len()),
foo.rs:49             None => break
foo.rs:50         };
foo.rs:51 
          ...
foo.rs:4:9: 4:23 note: lint level defined here
foo.rs:4 #![deny(while_let_loop)]
                 ^~~~~~~~~~~~~~
foo.rs:46:5: 53:6 help: try
while let Some(word) = s.split_whitespace().next() {
    let _ = (e, l);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions