Most structs are either ADT or Data, they shouldn't have a non-empty subset of pub fields.
The rule can be default allowed, since it may break some public APIs.
For pub(crate) or pub(mod path), it's commonly used as a friend class alternative, so I think we can treat them as private. If there are some requirements, we can add an option strict_partial_pub_fields later.
We can also introduce partial_pub_variants lint for enums later.
The lint can't be fixed automatically, since we don't know a struct is ADT or Data.
What it does
https://matklad.github.io//2022/05/29/binary-privacy.html
Most structs are either
ADT
orData
, they shouldn't have a non-empty subset of pub fields.The rule can be default allowed, since it may break some public APIs.
For
pub(crate)
orpub(mod path)
, it's commonly used as a friend class alternative, so I think we can treat them as private. If there are some requirements, we can add an optionstrict_partial_pub_fields
later.We can also introduce
partial_pub_variants
lint for enums later.The lint can't be fixed automatically, since we don't know a struct is
ADT
orData
.Lint Name
partial_pub_fields
Category
restriction
Advantage
Drawbacks
Example
Could be written as:
Could be written as: