unneeded_struct_pattern
triggers when matching 3rd-party crate's variant with { .. }
#14181
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
Turning a unit variant into a struct or tuple variant is a major breaking change.
Sometimes, downstream code that consumes an upstream crate's enum variants might care only about "which variant was chosen" and doesn't care whether the variant might (now or in the future) have associated data. In such a situation, I feel it isn't unreasonable to use
MyEnum::MyVariant { .. }
syntax regardless of whetherMyVariant
is a unit or not.Of course,
MyEnum::MyVariant
is sufficient syntax if the variant is a unit. But in this case, we don't "own" theMyEnum
type, and changes in the variant kind aren't up to us. Adding the{ .. }
is explicit about wishing to be future-proof to changes in the variant kind, so I think it shouldn't trigger a lint — especially not an on-by-default lint.Lint Name
unneeded_struct_pattern
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No lint reported. My code is saying "we don't care if this 3rd-party crate's variant becomes a tuple or struct variant in the future" and attempting to remain resilient to a potential future breaking change.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: