From 979b2ec659b0c36855e70efab9413e081c07b95b Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 28 Feb 2022 15:33:50 -0500 Subject: [PATCH 1/2] Stabilize `derive_default_enum` --- core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 660f6d92f..dc6bec246 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -167,7 +167,7 @@ #![feature(const_precise_live_drops)] #![feature(const_refs_to_cell)] #![feature(decl_macro)] -#![feature(derive_default_enum)] +#![cfg_attr(bootstrap, feature(derive_default_enum))] #![feature(deprecated_suggestion)] #![feature(doc_cfg)] #![feature(doc_notable_trait)] From 4f0b6df29f37c172dc5e0dc6f392fbb2248bf39d Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Tue, 8 Mar 2022 15:44:52 -0500 Subject: [PATCH 2/2] Add documentation --- core/src/default.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/src/default.rs b/core/src/default.rs index fb862f7df..1ce00828b 100644 --- a/core/src/default.rs +++ b/core/src/default.rs @@ -52,6 +52,23 @@ /// This trait can be used with `#[derive]` if all of the type's fields implement /// `Default`. When `derive`d, it will use the default value for each field's type. /// +/// ### `enum`s +/// +/// When using `#[derive(Default)]` on an `enum`, you need to choose which unit variant will be +/// default. You do this by placing the `#[default]` attribute on the variant. +/// +/// ``` +/// #[derive(Default)] +/// enum Kind { +/// #[default] +/// A, +/// B, +/// C, +/// } +/// ``` +/// +/// You cannot use the `#[default]` attribute on non-unit or non-exhaustive variants. +/// /// ## How can I implement `Default`? /// /// Provide an implementation for the `default()` method that returns the value of