Skip to content

manual_let_else incorrectly handling destructuring or-patterns #10708

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
ejmount opened this issue Apr 24, 2023 · 1 comment · Fixed by #10866
Closed

manual_let_else incorrectly handling destructuring or-patterns #10708

ejmount opened this issue Apr 24, 2023 · 1 comment · Fixed by #10866
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@ejmount
Copy link

ejmount commented Apr 24, 2023

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

@ejmount ejmount added the C-bug Category: Clippy is not doing the correct thing label Apr 24, 2023
@est31
Copy link
Member

est31 commented May 18, 2023

With #10797, or patterns will work, but only with tuple struct patterns like Some(v) or Ok(Enum::Variant(hi, _)). With that PR, the missing part is struct Foo::Bar { hello } patterns, similar to #10424.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants