Skip to content

single_element_loop: syntax error with never patterns ( missing parens) #12782

@matthiaskrgr

Description

@matthiaskrgr

Summary

.

Lint Name

single_element_loop

Reproducer

I tried this code:

#![feature(never_patterns)]
#![allow(incomplete_features)]
#![warn(clippy::single_element_loop)]
// edition: 2021

#[derive(Copy, Clone)]
enum Void {}

fn main() {
    let res_void: Result<bool, Void> = Ok(true);

    for (Ok(mut _x) | Err(!)) in [res_void] {
    // sugg:
    //{ let Ok(mut _x) | Err(!) = res_void;
       let ptr: *const Void = std::ptr::null();
    }
}

I saw this happen:
suggestion does not build:

error: top-level or-patterns are not allowed in `let` bindings
  --> seloop.rs:11:11
   |
11 |     { let Ok(mut _x) | Err(!) = res_void;
   |           ^^^^^^^^^^^^^^^^^^^ help: wrap the pattern in parentheses: `(Ok(mut _x) | Err(!))`

Version

rustc 1.80.0-nightly (faefc618c 2024-05-07)
binary: rustc
commit-hash: faefc618cf48bd794cbc808448df1bf3f59f36af
commit-date: 2024-05-07
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions