Closed
Description
Summary
The manual_let_else lint does not use the mut
modifier in the suggestion even though the original is mut
. This makes the code error when the suggestion is applied.
Reproducer
I tried this code:
let mut reader = match self.reader.lock() {
Ok(reader) => reader,
Err(_) => {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"reader panicked in another thread",
))
}
};
I expected to see this happen:
warning: this could be rewritten as `let...else`
--> toolkit/src/utils.rs:149:9
|
149 | / let mut reader = match self.reader.lock() {
150 | | Ok(reader) => reader,
151 | | Err(_) => {
152 | | return Err(io::Error::new(
... |
156 | | }
157 | | };
| |__________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
= note: `#[warn(clippy::manual_let_else)]` implied by `#[warn(clippy::pedantic)]`
help: consider writing
|
149 ~ let Ok(mut reader) = self.reader.lock() else {
150 + return Err(io::Error::new(
151 + io::ErrorKind::UnexpectedEof,
152 + "reader panicked in another thread",
153 + ))
154 + };
|
Instead, this happened:
warning: this could be rewritten as `let...else`
--> toolkit/src/utils.rs:149:9
|
149 | / let mut reader = match self.reader.lock() {
150 | | Ok(reader) => reader,
151 | | Err(_) => {
152 | | return Err(io::Error::new(
... |
156 | | }
157 | | };
| |__________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
= note: `#[warn(clippy::manual_let_else)]` implied by `#[warn(clippy::pedantic)]`
help: consider writing
|
149 ~ let Ok(reader) = self.reader.lock() else {
150 + return Err(io::Error::new(
151 + io::ErrorKind::UnexpectedEof,
152 + "reader panicked in another thread",
153 + ))
154 + };
|
Version
rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error