Closed
Description
Summary
The code suggestion of clippy doesn't work.
warning: this match could be written as a `let` statement
--> src/html_output.rs:59:19
|
59 | val = match val.split_at(idx) {
| ___________________^
60 | | (pre, suf) => {
61 | | pre.write_to(out)?;
62 | | suf
63 | | }
64 | | };
| |_____________^
|
= note: `#[warn(clippy::match_single_binding)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
help: consider using `let` statement
|
59 ~ val = let (pre, suf) = val.split_at(idx);
60 + {
61 + pre.write_to(out)?;
62 + suf
63 ~ };
|
Reproducer
I tried this code:
fn main() {
let (mut val, idx) = ("a b", 1);
val = match val.split_at(idx) {
(pre, suf) => {
println!("{}", pre);
suf
}
};
let _ = val;
}
I expected to see this happen:
59 ~ val = {
60 + let (pre, suf) = val.split_at(idx);
61 + pre.write_to(out)?;
62 + suf
63 ~ };
Instead, this happened:
59 ~ val = let (pre, suf) = val.split_at(idx);
60 + {
61 + pre.write_to(out)?;
62 + suf
63 ~ };
Version
rustc 1.62.0-nightly (311e2683e 2022-04-18)
binary: rustc
commit-hash: 311e2683e1bad87715b1558f7900e294d24ce491
commit-date: 2022-04-18
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1
clippy 0.1.62 (311e268 2022-04-18)
Additional Labels
No response