You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kriskras99 opened this issue
Mar 1, 2023
· 2 comments
· Fixed by #10797
Labels
C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
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:
letmut reader = matchself.reader.lock(){Ok(reader) => reader,Err(_) => {returnErr(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 + };
|
I think this was fixed by #10175. PR #10797 is adding a test for a case with mut. Note that it will not work in all cases, as non-tuple structs aren't supported. But for the example you gave, it will correctly put the mut.
C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
The manual_let_else lint does not use the
mut
modifier in the suggestion even though the original ismut
. This makes the code error when the suggestion is applied.Reproducer
I tried this code:
I expected to see this happen:
Instead, this happened:
Version
Additional Labels
@rustbot label +
I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: