Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matthiaskrgr opened this issue May 8, 2024 · 0 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

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

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 8, 2024
@matthiaskrgr matthiaskrgr changed the title single_element_loop: syntax error with never patterns ( missing parents) single_element_loop: syntax error with never patterns ( missing parens) May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

1 participant