-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for RFC 3107: derive_default_enum #87517
Comments
Implementation PR was already created: #86735 |
Implementation has landed. |
Actually, this is a duplicate of #86985. As the tracking issue in code links to this, I'll close that even though it was opened first. Unresolved question for the record:
|
rust-lang/rust#87517 started standardising `#[default]` as an attribute on enum variants, support it compatibly identically to `#[num_enum(default)]`.
rust-lang/rust#87517 started standardising `#[default]` as an attribute on enum variants, support it compatibly identically to `#[num_enum(default)]`.
rust-lang/rust#87517 started standardising `#[default]` as an attribute on enum variants, support it compatibly identically to `#[num_enum(default)]`.
@jhpratt @pnkfelix I've seen this in the Unresolved Questions section of the duplicate #86985, but it doesn't show up in this issue (only after three comments when @jhpratt points it out). I think, we should put it here in the Unresolved Questions section as well, so people see it at first glance and don't have to scroll three comments to see it (and therefore don't miss it that easily). |
With #88681 being merged, I'm inclined to resolve the question of multiple |
https://github.com/rust-lang/rust/blob/master/src/test/ui/feature-gates/feature-gate-derive_default_enum.stderr still points at #86735. this file was the most "useful" result when I searched the feature gate on the repository/ |
This comment was marked as resolved.
This comment was marked as resolved.
To match the actual implementation, the RFC text was updated to use the |
How do people feel about stabilizing this? There was a minor concern from @Mark-Simulacrum in #92366, but that's a diagnostic that can be changed at any time. The implementation is straightforward, tested, used in rustc, and has remained unchanged for ~7 months. |
Stabilization PR: #94457 |
Stabilization reportSummaryAn attribute #[derive(Default)]
enum Padding {
Space,
Zero,
#[default]
None,
}
assert_eq!(Padding::default(), Padding::None); The Test cases
DocumentationPR to update the reference will be made shortly. Unresolved questionsThere was one: whether multiple |
@rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
No matter whose jurisdiction it is, this seems really useful, +1 from me. I would like a few more knobs on our derives. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
So, here's an interesting thing that I didn't see brought up, that I don't think should block stabilisation of the base feature, but should probably be mentioned. What about unions? #[derive(Default)]
pub union Thing {
#[default]
one: One,
two: Two,
three: Three,
} We could easily make this create the below implementation: impl Default for Thing {
fn default() -> Thing {
Thing { one: One::default() }
}
} |
That seems like a reasonable future possibility. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). `@rustbot` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ``@rustbot`` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ```@rustbot``` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ````@rustbot```` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). `````@rustbot````` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ``````@rustbot`````` label +S-waiting-on-review +T-lang
…um, r=davidtwco Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](rust-lang/rfcs#3107) and tracked in rust-lang#87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ```````@rustbot``````` label +S-waiting-on-review +T-lang
Triage: the stabilization PR (#94457) has landed 🎉 Closing as done. |
I don't know if this is the right place to ask, but why is it that
? I feel like a more natural behavior would be to behave like #[derive(Default)]
struct Foo<T>(T); will only be #[derive(Default)]
pub enum Error<T> {
#[default]
Message(T),
Other,
} would only be |
@alexschrod How about these cases? #[derive(Default)]
pub enum Either<A, B> {
#[default]
One(A),
Two(B),
} Does that require only How about this? #[derive(Default)]
pub enum MaybeOption<T> {
#[default]
Yes(Option<T>),
No,
} Does that require |
It makes sense that for a |
Because Since it's not using the "we put the bound on all the generic parameters" approach, this is a great future-proofing until it's decided whether it should ever do anything else. Maybe we'll one day get "perfect derive" (https://smallcultfollowing.com/babysteps//blog/2022/04/12/implied-bounds-and-perfect-derive/) that will give a different way to do this for everything, and that's when the rules will change. |
Thanks for the explanation, @scottmcm, it makes sense to me now that this first version is intentionally conservative with regard to a less problematic possible future improvement. |
This is a tracking issue for the RFC 3107: "
#[derive(Default)]
on enums with a#[default]
attribute" (rust-lang/rfcs#3107).The feature gate for the issue is
#![feature(derive_default_enum)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
instructions?)
derive_default_enum
#94457) (see instructions on rustc-dev-guide)Unresolved Questions
None so far
Implementation history
The text was updated successfully, but these errors were encountered: