Stabilize `derive_default_enum`

This commit is contained in:
Jacob Pratt 2022-02-28 15:33:50 -05:00
parent e745b4ddbd
commit abf2b4c04d
No known key found for this signature in database
GPG Key ID: B80E19E4662B5AA4
15 changed files with 38 additions and 73 deletions

View File

@ -46,18 +46,7 @@ pub fn expand_deriving_default(
StaticStruct(_, fields) => { StaticStruct(_, fields) => {
default_struct_substructure(cx, trait_span, substr, fields) default_struct_substructure(cx, trait_span, substr, fields)
} }
StaticEnum(enum_def, _) => { StaticEnum(enum_def, _) => default_enum_substructure(cx, trait_span, enum_def),
if !cx.sess.features_untracked().derive_default_enum {
rustc_session::parse::feature_err(
cx.parse_sess(),
sym::derive_default_enum,
span,
"deriving `Default` on enums is experimental",
)
.emit();
}
default_enum_substructure(cx, trait_span, enum_def)
}
_ => cx.span_bug(trait_span, "method in `derive(Default)`"), _ => cx.span_bug(trait_span, "method in `derive(Default)`"),
} }
})), })),

View File

@ -126,6 +126,8 @@ declare_features! (
(accepted, default_type_params, "1.0.0", None, None), (accepted, default_type_params, "1.0.0", None, None),
/// Allows `#[deprecated]` attribute. /// Allows `#[deprecated]` attribute.
(accepted, deprecated, "1.9.0", Some(29935), None), (accepted, deprecated, "1.9.0", Some(29935), None),
/// Allows `#[derive(Default)]` and `#[default]` on enums.
(accepted, derive_default_enum, "1.62.0", Some(86985), None),
/// Allows the use of destructuring assignments. /// Allows the use of destructuring assignments.
(accepted, destructuring_assignment, "1.59.0", Some(71126), None), (accepted, destructuring_assignment, "1.59.0", Some(71126), None),
/// Allows `#[doc(alias = "...")]`. /// Allows `#[doc(alias = "...")]`.

View File

@ -368,8 +368,6 @@ declare_features! (
(active, deprecated_safe, "1.61.0", Some(94978), None), (active, deprecated_safe, "1.61.0", Some(94978), None),
/// Allows having using `suggestion` in the `#[deprecated]` attribute. /// Allows having using `suggestion` in the `#[deprecated]` attribute.
(active, deprecated_suggestion, "1.61.0", Some(94785), None), (active, deprecated_suggestion, "1.61.0", Some(94785), None),
/// Allows `#[derive(Default)]` and `#[default]` on enums.
(active, derive_default_enum, "1.56.0", Some(86985), None),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(active, doc_auto_cfg, "1.58.0", Some(43781), None), (active, doc_auto_cfg, "1.58.0", Some(43781), None),
/// Allows `#[doc(cfg(...))]`. /// Allows `#[doc(cfg(...))]`.

View File

@ -11,7 +11,7 @@
//! even if it is stabilized or removed, *do not remove it*. Instead, move the //! even if it is stabilized or removed, *do not remove it*. Instead, move the
//! symbol to the `accepted` or `removed` modules respectively. //! symbol to the `accepted` or `removed` modules respectively.
#![feature(derive_default_enum)] #![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(once_cell)] #![feature(once_cell)]
mod accepted; mod accepted;

View File

@ -17,7 +17,7 @@
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(derive_default_enum)] #![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(extend_one)] #![feature(extend_one)]
#![feature(label_break_value)] #![feature(label_break_value)]
#![feature(let_chains)] #![feature(let_chains)]

View File

@ -30,7 +30,7 @@
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(derive_default_enum)] #![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(discriminant_kind)] #![feature(discriminant_kind)]
#![feature(exhaustive_patterns)] #![feature(exhaustive_patterns)]
#![feature(get_mut_unchecked)] #![feature(get_mut_unchecked)]

View File

@ -1,7 +1,7 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(derive_default_enum)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(let_else)] #![feature(let_else)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]

View File

@ -16,7 +16,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(derive_default_enum)] #![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(hash_drain_filter)] #![feature(hash_drain_filter)]
#![feature(label_break_value)] #![feature(label_break_value)]

View File

@ -167,7 +167,7 @@
#![feature(const_precise_live_drops)] #![feature(const_precise_live_drops)]
#![feature(const_refs_to_cell)] #![feature(const_refs_to_cell)]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(derive_default_enum)] #![cfg_attr(bootstrap, feature(derive_default_enum))]
#![feature(deprecated_suggestion)] #![feature(deprecated_suggestion)]
#![feature(doc_cfg)] #![feature(doc_cfg)]
#![feature(doc_notable_trait)] #![feature(doc_notable_trait)]

View File

@ -1,7 +1,5 @@
// run-pass // run-pass
#![feature(derive_default_enum)]
// nb: does not impl Default // nb: does not impl Default
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
struct NotDefault; struct NotDefault;

View File

@ -5,7 +5,6 @@
#![feature(lang_items)] #![feature(lang_items)]
#![feature(no_core)] #![feature(no_core)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(derive_default_enum)]
#![no_core] #![no_core]

View File

@ -1,7 +0,0 @@
#[derive(Default)] //~ ERROR deriving `Default` on enums is experimental
enum Foo {
#[default]
Alpha,
}
fn main() {}

View File

@ -1,13 +0,0 @@
error[E0658]: deriving `Default` on enums is experimental
--> $DIR/feature-gate-derive_default_enum.rs:1:10
|
LL | #[derive(Default)]
| ^^^^^^^
|
= note: see issue #86985 <https://github.com/rust-lang/rust/issues/86985> for more information
= help: add `#![feature(derive_default_enum)]` to the crate attributes to enable
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -5,7 +5,6 @@
#![feature(trace_macros, concat_idents)] #![feature(trace_macros, concat_idents)]
#![feature(stmt_expr_attributes, arbitrary_enum_discriminant)] #![feature(stmt_expr_attributes, arbitrary_enum_discriminant)]
#![feature(derive_default_enum)]
use std::arch::asm; use std::arch::asm;

View File

@ -1,41 +1,41 @@
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:14:5 --> $DIR/macros-nonfatal-errors.rs:13:5
| |
LL | #[default] LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:19:36 --> $DIR/macros-nonfatal-errors.rs:18:36
| |
LL | struct DefaultInnerAttrTupleStruct(#[default] ()); LL | struct DefaultInnerAttrTupleStruct(#[default] ());
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:23:1 --> $DIR/macros-nonfatal-errors.rs:22:1
| |
LL | #[default] LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:27:1 --> $DIR/macros-nonfatal-errors.rs:26:1
| |
LL | #[default] LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:37:11 --> $DIR/macros-nonfatal-errors.rs:36:11
| |
LL | Foo = #[default] 0, LL | Foo = #[default] 0,
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:38:14 --> $DIR/macros-nonfatal-errors.rs:37:14
| |
LL | Bar([u8; #[default] 1]), LL | Bar([u8; #[default] 1]),
| ^^^^^^^^^^ | ^^^^^^^^^^
error: no default declared error: no default declared
--> $DIR/macros-nonfatal-errors.rs:43:10 --> $DIR/macros-nonfatal-errors.rs:42:10
| |
LL | #[derive(Default)] LL | #[derive(Default)]
| ^^^^^^^ | ^^^^^^^
@ -44,7 +44,7 @@ LL | #[derive(Default)]
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error: multiple declared defaults error: multiple declared defaults
--> $DIR/macros-nonfatal-errors.rs:49:10 --> $DIR/macros-nonfatal-errors.rs:48:10
| |
LL | #[derive(Default)] LL | #[derive(Default)]
| ^^^^^^^ | ^^^^^^^
@ -62,7 +62,7 @@ LL | Baz,
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `#[default]` attribute does not accept a value error: `#[default]` attribute does not accept a value
--> $DIR/macros-nonfatal-errors.rs:61:5 --> $DIR/macros-nonfatal-errors.rs:60:5
| |
LL | #[default = 1] LL | #[default = 1]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
@ -70,7 +70,7 @@ LL | #[default = 1]
= help: try using `#[default]` = help: try using `#[default]`
error: multiple `#[default]` attributes error: multiple `#[default]` attributes
--> $DIR/macros-nonfatal-errors.rs:69:5 --> $DIR/macros-nonfatal-errors.rs:68:5
| |
LL | #[default] LL | #[default]
| ---------- `#[default]` used here | ---------- `#[default]` used here
@ -81,13 +81,13 @@ LL | Foo,
| |
= note: only one `#[default]` attribute is needed = note: only one `#[default]` attribute is needed
help: try removing this help: try removing this
--> $DIR/macros-nonfatal-errors.rs:68:5 --> $DIR/macros-nonfatal-errors.rs:67:5
| |
LL | #[default] LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
error: multiple `#[default]` attributes error: multiple `#[default]` attributes
--> $DIR/macros-nonfatal-errors.rs:79:5 --> $DIR/macros-nonfatal-errors.rs:78:5
| |
LL | #[default] LL | #[default]
| ---------- `#[default]` used here | ---------- `#[default]` used here
@ -99,7 +99,7 @@ LL | Foo,
| |
= note: only one `#[default]` attribute is needed = note: only one `#[default]` attribute is needed
help: try removing these help: try removing these
--> $DIR/macros-nonfatal-errors.rs:76:5 --> $DIR/macros-nonfatal-errors.rs:75:5
| |
LL | #[default] LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -109,7 +109,7 @@ LL | #[default]
| ^^^^^^^^^^ | ^^^^^^^^^^
error: the `#[default]` attribute may only be used on unit enum variants error: the `#[default]` attribute may only be used on unit enum variants
--> $DIR/macros-nonfatal-errors.rs:86:5 --> $DIR/macros-nonfatal-errors.rs:85:5
| |
LL | Foo {}, LL | Foo {},
| ^^^ | ^^^
@ -117,7 +117,7 @@ LL | Foo {},
= help: consider a manual implementation of `Default` = help: consider a manual implementation of `Default`
error: default variant must be exhaustive error: default variant must be exhaustive
--> $DIR/macros-nonfatal-errors.rs:94:5 --> $DIR/macros-nonfatal-errors.rs:93:5
| |
LL | #[non_exhaustive] LL | #[non_exhaustive]
| ----------------- declared `#[non_exhaustive]` here | ----------------- declared `#[non_exhaustive]` here
@ -127,37 +127,37 @@ LL | Foo,
= help: consider a manual implementation of `Default` = help: consider a manual implementation of `Default`
error: asm template must be a string literal error: asm template must be a string literal
--> $DIR/macros-nonfatal-errors.rs:99:10 --> $DIR/macros-nonfatal-errors.rs:98:10
| |
LL | asm!(invalid); LL | asm!(invalid);
| ^^^^^^^ | ^^^^^^^
error: concat_idents! requires ident args error: concat_idents! requires ident args
--> $DIR/macros-nonfatal-errors.rs:102:5 --> $DIR/macros-nonfatal-errors.rs:101:5
| |
LL | concat_idents!("not", "idents"); LL | concat_idents!("not", "idents");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: argument must be a string literal error: argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:104:17 --> $DIR/macros-nonfatal-errors.rs:103:17
| |
LL | option_env!(invalid); LL | option_env!(invalid);
| ^^^^^^^ | ^^^^^^^
error: expected string literal error: expected string literal
--> $DIR/macros-nonfatal-errors.rs:105:10 --> $DIR/macros-nonfatal-errors.rs:104:10
| |
LL | env!(invalid); LL | env!(invalid);
| ^^^^^^^ | ^^^^^^^
error: expected string literal error: expected string literal
--> $DIR/macros-nonfatal-errors.rs:106:10 --> $DIR/macros-nonfatal-errors.rs:105:10
| |
LL | env!(foo, abr, baz); LL | env!(foo, abr, baz);
| ^^^ | ^^^
error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined
--> $DIR/macros-nonfatal-errors.rs:107:5 --> $DIR/macros-nonfatal-errors.rs:106:5
| |
LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -165,7 +165,7 @@ LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST");
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
error: format argument must be a string literal error: format argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:109:13 --> $DIR/macros-nonfatal-errors.rs:108:13
| |
LL | format!(invalid); LL | format!(invalid);
| ^^^^^^^ | ^^^^^^^
@ -176,19 +176,19 @@ LL | format!("{}", invalid);
| +++++ | +++++
error: argument must be a string literal error: argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:111:14 --> $DIR/macros-nonfatal-errors.rs:110:14
| |
LL | include!(invalid); LL | include!(invalid);
| ^^^^^^^ | ^^^^^^^
error: argument must be a string literal error: argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:113:18 --> $DIR/macros-nonfatal-errors.rs:112:18
| |
LL | include_str!(invalid); LL | include_str!(invalid);
| ^^^^^^^ | ^^^^^^^
error: couldn't read $DIR/i'd be quite surprised if a file with this name existed: $FILE_NOT_FOUND_MSG (os error 2) error: couldn't read $DIR/i'd be quite surprised if a file with this name existed: $FILE_NOT_FOUND_MSG (os error 2)
--> $DIR/macros-nonfatal-errors.rs:114:5 --> $DIR/macros-nonfatal-errors.rs:113:5
| |
LL | include_str!("i'd be quite surprised if a file with this name existed"); LL | include_str!("i'd be quite surprised if a file with this name existed");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -196,13 +196,13 @@ LL | include_str!("i'd be quite surprised if a file with this name existed")
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
error: argument must be a string literal error: argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:115:20 --> $DIR/macros-nonfatal-errors.rs:114:20
| |
LL | include_bytes!(invalid); LL | include_bytes!(invalid);
| ^^^^^^^ | ^^^^^^^
error: couldn't read $DIR/i'd be quite surprised if a file with this name existed: $FILE_NOT_FOUND_MSG (os error 2) error: couldn't read $DIR/i'd be quite surprised if a file with this name existed: $FILE_NOT_FOUND_MSG (os error 2)
--> $DIR/macros-nonfatal-errors.rs:116:5 --> $DIR/macros-nonfatal-errors.rs:115:5
| |
LL | include_bytes!("i'd be quite surprised if a file with this name existed"); LL | include_bytes!("i'd be quite surprised if a file with this name existed");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -210,13 +210,13 @@ LL | include_bytes!("i'd be quite surprised if a file with this name existed
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: trace_macros! accepts only `true` or `false` error: trace_macros! accepts only `true` or `false`
--> $DIR/macros-nonfatal-errors.rs:118:5 --> $DIR/macros-nonfatal-errors.rs:117:5
| |
LL | trace_macros!(invalid); LL | trace_macros!(invalid);
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error: cannot find macro `llvm_asm` in this scope error: cannot find macro `llvm_asm` in this scope
--> $DIR/macros-nonfatal-errors.rs:100:5 --> $DIR/macros-nonfatal-errors.rs:99:5
| |
LL | llvm_asm!(invalid); LL | llvm_asm!(invalid);
| ^^^^^^^^ | ^^^^^^^^