-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Detect Enum Objects with empty attribute body using {}
#12007
Comments
{}
{}
@rustbot claim |
This is already handled by EDIT: It seems like it doesn't, it just focuses on structs. I think it'd be better to mix the current open PR with that lint instead of making a whole new lint. (Maybe with a name change to the current lint) |
{}
{}
A new lint called |
A merged lint would mean deprecating the previous one. I think a better way to handle this is to have both lints in the same file with a sufficiently descriptive name, and issuing the right one. This pattern already exists in a few places, so it's established. |
Changing pub enum Decoder {
Absent {},
Symbol(u8)
} into pub enum Decoder {
Absent,
Symbol(u8)
} is a breaking change. Can we determine if the user intends to do this? Also, we're not enabling this lint by default, correct? |
The lint would be placed in the "Restriction" Group which seems to have lints that are |
I have opened a new PR incorporating the changes suggested by @partiallytyped. |
What it does
The proposed lint feature aims to improve code readability and consistency by discouraging the use of empty attribute objects
{}
succeeding structures without attributes. In Rust, empty attribute objects are often used to represent variants of an enum that carry no additional information. However, this usage can be misleading and may result in less expressive and clear code.This lint feature shall check for the presence of empty attribute objects {} immediately following enum variants without associated data. If such a pattern is detected, the lint will emit a warning. This warning encourages developers to reconsider the necessity of the empty attribute object and suggests using the enum variant directly without the unnecessary attribute object.
Advantage
Drawbacks
No response
Example
Could be written as:
In both cases, the nursery and the pedantic mode of
clippy
do not output any warnings nor errors. To prevent code blow, structures without attributes shall not be allowed to be succeeded by an empty attribute object,{}
. The example shall result in a warning, while the second one should not.Tasks
The text was updated successfully, but these errors were encountered: