Skip to content

manual_let_else incorrectly handling destructuring or-patterns  #10708

Closed
@ejmount

Description

@ejmount

Summary

Similar to #9938, clippy now correctly suggests the brackets, but fails to take into account the pattern it's replacing is binding names for further use.

Reproducer

I tried this code:

let data_name = match &data_item {
        Item::Struct(ItemStruct { ident , ..})
        | Item::Enum(ItemEnum { ident , ..})
        | Item::Union(ItemUnion { ident , ..}) => ident,
        _ => unreachable!(),
    };

I expected to see this suggested:

    let (Item::Struct(ItemStruct { ident: data_name, .. })
        | Item::Enum(ItemEnum { ident: data_name, .. })
        | Item::Union(ItemUnion { ident: data_name, .. })) = &data_item else { unreachable!() };

Instead, this happened:

...help: consider writing
   |
69 ~     let (Item::Struct(ItemStruct { ident, .. })
70 +         | Item::Enum(ItemEnum { ident, .. })
71 +         | Item::Union(ItemUnion { ident, .. })) = &data_item else { unreachable!() };
   |

Version

rustc 1.71.0-nightly (7f94b314c 2023-04-23)
binary: rustc
commit-hash: 7f94b314cead7059a71a265a8b64905ef2511796
commit-date: 2023-04-23
host: x86_64-pc-windows-msvc
release: 1.71.0-nightly
LLVM version: 16.0.2

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