Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[manual_let_else] does not copy mut modifier #10431

Closed
Kriskras99 opened this issue Mar 1, 2023 · 2 comments · Fixed by #10797
Closed

[manual_let_else] does not copy mut modifier #10431

Kriskras99 opened this issue Mar 1, 2023 · 2 comments · Fixed by #10797
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Kriskras99
Copy link

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

@Kriskras99 Kriskras99 added the C-bug Category: Clippy is not doing the correct thing label Mar 1, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2023

Error: Label I-suggestion-causes-error can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@Alexendoo Alexendoo added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 1, 2023
@est31
Copy link
Member

est31 commented May 18, 2023

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants