-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement RFC 3107: #[derive(Default)]
on enums with a #[default]
attribute
#86735
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
I think the implementation is a detail that doesn't matter to the lang or libs-api teams, this should be reviewed by the compiler team. |
You'll need to create the feature gate:
Once this is done, you should be able to define the attribute like this: gated!(Default, AssumedUsed, template!(Word), derive_default_enum, experimental!(derive_default_enum)), Apparently This should take care of checking that the attribute is only used on nightly, you don't have to manually implement it. However, you might want to implement a check to emit an error if the attribute is used outside an enum variant. |
@rustbot label -T-libs-api +T-compiler I found the page in the dev guide last night, and had it generally in the right place. When using the line you provided (a slight difference from what I had), I get the following error in a number of places
Given that While it may work by declaring the attribute globally and erroring if it's used in certain places, it feels like it should be better if there's a way for the derive to declare the attribute belongs to it. I presume this is possible given that it's exposed for |
I guess this proves I'm not the right reviewer here, r? @petrochenkov maybe |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Changes have been made. |
The RFC has been merged. cc @petrochenkov |
@bors r+ |
📌 Commit 7f036962daeaa8210a109441112474bc9a58f6cf has been approved by |
This comment has been minimized.
This comment has been minimized.
This avoids the need for tools like rust-analyzer to implement these suggestions themselves.
Rebased. Also bumped to 1.56 given the 1.55 beta has been cut. |
@bors r+ |
📌 Commit 72465b0 has been approved by |
☀️ Test successful - checks-actions |
This PR implements RFC 3107, which permits
#[derive(Default)]
on enums where a unit variant has a#[default]
attribute. See comments for current status.