Skip to content

manual_let_else suggests incorrect code change #13768

New issue

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

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

Already on GitHub? Sign in to your account

Closed
nyurik opened this issue Dec 1, 2024 · 1 comment · Fixed by #14204
Closed

manual_let_else suggests incorrect code change #13768

nyurik opened this issue Dec 1, 2024 · 1 comment · Fixed by #14204
Assignees
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

@nyurik
Copy link
Contributor

nyurik commented Dec 1, 2024

Summary

Having a ref modifier in the match statement is incorrectly dropped from the suggested code

Reproducer

I tried this code:

#![warn(clippy::manual_let_else)]

#[derive(Debug)]
enum TypeKind {
    Str(String),
    None,
}

fn bar(value: &String) {
    println!("Value: {value}");
}

fn foo(value: TypeKind) {
    let signature = match value {
        TypeKind::Str(ref val) => val,
        _ => {
            println!("No signature found");
            return;
        },
    };

    bar(signature);
}

fn main() {
    foo(TypeKind::Str("Hello".to_string()));
    foo(TypeKind::None);
}

I expected the match value {...} statement to be converted to this:

let TypeKind::Str(ref signature) = value else {
    println!("No signature found");
    return;
};

Instead, the suggestion is missing the ref keyword

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

@rustbot label +I-suggestion-causes-error

@nyurik nyurik added the C-bug Category: Clippy is not doing the correct thing label Dec 1, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 1, 2024
@profetia
Copy link
Contributor

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue Mar 8, 2025
fixes #13768

The existing implemention forgets to handle the binding mode (i.e. `ref`
and `ref mut`), so I just modified it to cover these cases.

changelog: [`manual_let_else`]: fix missing binding mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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.

3 participants