Skip to content

bool_to_int_with_if bad fix suggestion for if let #9809

@alexheretic

Description

@alexheretic

Summary

When auto-fixing a particular bool_to_int_with_if the code fix does not compile. The current suggestion does not seem to work with if let.

Reproducer

I tried this code:

enum Kind {
    A,
    #[allow(dead_code)]
    B,
}

fn main() {
    let kind = Kind::A;
    let kind_num = if let Kind::A = kind { 1u8 } else { 0 };
    eprintln!("{kind_num}");
}

This produces the following bad suggestion.

let kind_num = u8::from(let Kind::A = kind);

Version

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions