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

Manual let else suggests fix that doesn't compile #11579

Closed
barafael opened this issue Sep 28, 2023 · 0 comments · Fixed by #11580
Closed

Manual let else suggests fix that doesn't compile #11579

barafael opened this issue Sep 28, 2023 · 0 comments · Fixed by #11580
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@barafael
Copy link

barafael commented Sep 28, 2023

Summary

While running clippy in pedantic mode, I got this "manual_let_else" diagnostic from clippy (see below).
The fix suggestion surprised me. I don't think it is valid syntax (though it does look very nice).

Reproducer

I tried this code:

let msg = match Some("hi") {
    Some(m) => m,
    _ => unreachable!("can't happen"),
};

I expected to see this happen:

warning: this could be rewritten as `let...else`
 --> src\main.rs:2:5
  |
2 | /     let msg = match Some("hi") {
3 | |         Some(x) => x,
4 | |         _ => unreachable!("can't happen"),
5 | |     };
  | |______^ help: consider writing: `let Some(msg) = Some("hi") else { unreachable!("can't happen") };`

Instead, this happened:

warning: this could be rewritten as `let...else`
 --> src\main.rs:2:5
  |
2 | /     let msg = match Some("hi") {
3 | |         Some(x) => x,
4 | |         _ => unreachable!("can't happen"),
5 | |     };
  | |______^ help: consider writing: `let Some(msg) = Some("hi") else unreachable!("can't happen");`

Version

rustc 1.74.0-nightly (3223b0b5e 2023-09-20)
binary: rustc
commit-hash: 3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e
commit-date: 2023-09-20
host: x86_64-pc-windows-msvc
release: 1.74.0-nightly
LLVM version: 17.0.0

Additional Labels

No response

@barafael barafael added the C-bug Category: Clippy is not doing the correct thing label Sep 28, 2023
@bors bors closed this as completed in b00236d Sep 29, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant