Skip to content
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

manual_let_else suggests incorrect code change #13768

Open
nyurik opened this issue Dec 1, 2024 · 0 comments
Open

manual_let_else suggests incorrect code change #13768

nyurik opened this issue Dec 1, 2024 · 0 comments
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
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

No branches or pull requests

2 participants