Closed
Description
Summary
manual_let_else
can propose replacements that change the behaviour of the code
Permalink to the reproducer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6719a7919c90a17b495f991566e423c, tested 2023-01-26
Lint Name
manual_let_else
Reproducer
I tried this code:
#![warn(clippy::manual_let_else)]
fn main() {
let data = [1_u8, 2, 3, 4, 0, 0, 0, 0];
// Rewriting as let-else would break this match because [data @ ..] (last pattern) matches everything.
let data = match data.as_slice() {
[] | [0, 0] => return,
[data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ ..] => data,
};
dbg!(data);
}
I saw this happen:
#![warn(clippy::manual_let_else)]
fn main() {
let data = [1_u8, 2, 3, 4, 0, 0, 0, 0];
// Rewriting as let-else would break this match because [data @ ..] (last pattern) matches everything.
let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ ..]) = data.as_slice() else {
return;
};
dbg!(data);
}
I expected to see this happen:
No replacement is proposed
Version
- rust-clippy 0.1.68 (2023-01-26 d7948c8) (playground)
Additional Labels
No response