New lint: public API struct became enum or union #954
Labels
A-lint
Area: new or existing lint
E-help-wanted
Call for participation: Help is requested to fix this issue.
E-mentor
Call for participation: Mentorship is available for this issue.
Inspired by this post: https://internals.rust-lang.org/t/rest-patterns-foo-should-match-non-struct-types/21607
TL;DR: Given a type
Example
, the pattern inmatches!(value, Example { .. })
is only valid ifExample
is a struct. It fails on both enums and unions at the moment: playgroundWe already have a similar lint for changing a public API struct with public fields into an enum or union:
struct_with_pub_fields_changed_type
. The breakage there is more compelling than "empty pattern match" so we should keep that lint. We should make the new lints disjoint from it, so that users see one or the other but never both.We also have a lint for constructible structs changing to another type:
constructible_struct_changed_type
. The breakage there is also more compelling than "empty pattern match" so we should keep that lint too. The new lints should be disjoint from it as well.The new lints here should therefore be:
struct_with_no_pub_fields_changed
#962#[non_exhaustive]
struct with no fields of any kind is no longer a struct: feat: add lintstruct_marked_non_exhaustive_changed_type
#963The new lints will be quite similar to the related lints mentioned above. Make sure to check out our contributing guide, and take a look at what prior lints' merged PRs looked like so you know what to expect. It's easier than you think!
Thanks to @jhpratt for bringing this to my attention!
The text was updated successfully, but these errors were encountered: