Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwco
Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](https://github.com/rust-lang/rfcs/pull/3107) and tracked in #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
This commit is contained in:
commit
27e2d811e6
16 changed files with 55 additions and 73 deletions
|
|
@ -1,7 +1,5 @@
|
|||
// run-pass
|
||||
|
||||
#![feature(derive_default_enum)]
|
||||
|
||||
// nb: does not impl Default
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct NotDefault;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#![feature(lang_items)]
|
||||
#![feature(no_core)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(derive_default_enum)]
|
||||
|
||||
#![no_core]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#[derive(Default)] //~ ERROR deriving `Default` on enums is experimental
|
||||
enum Foo {
|
||||
#[default]
|
||||
Alpha,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -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`.
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#![feature(trace_macros, concat_idents)]
|
||||
#![feature(stmt_expr_attributes, arbitrary_enum_discriminant)]
|
||||
#![feature(derive_default_enum)]
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
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]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
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] ());
|
||||
| ^^^^^^^^^^
|
||||
|
||||
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]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
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]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
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,
|
||||
| ^^^^^^^^^^
|
||||
|
||||
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]),
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: no default declared
|
||||
--> $DIR/macros-nonfatal-errors.rs:43:10
|
||||
--> $DIR/macros-nonfatal-errors.rs:42:10
|
||||
|
|
||||
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)
|
||||
|
||||
error: multiple declared defaults
|
||||
--> $DIR/macros-nonfatal-errors.rs:49:10
|
||||
--> $DIR/macros-nonfatal-errors.rs:48:10
|
||||
|
|
||||
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)
|
||||
|
||||
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]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -70,7 +70,7 @@ LL | #[default = 1]
|
|||
= help: try using `#[default]`
|
||||
|
||||
error: multiple `#[default]` attributes
|
||||
--> $DIR/macros-nonfatal-errors.rs:69:5
|
||||
--> $DIR/macros-nonfatal-errors.rs:68:5
|
||||
|
|
||||
LL | #[default]
|
||||
| ---------- `#[default]` used here
|
||||
|
|
@ -81,13 +81,13 @@ LL | Foo,
|
|||
|
|
||||
= note: only one `#[default]` attribute is needed
|
||||
help: try removing this
|
||||
--> $DIR/macros-nonfatal-errors.rs:68:5
|
||||
--> $DIR/macros-nonfatal-errors.rs:67:5
|
||||
|
|
||||
LL | #[default]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: multiple `#[default]` attributes
|
||||
--> $DIR/macros-nonfatal-errors.rs:79:5
|
||||
--> $DIR/macros-nonfatal-errors.rs:78:5
|
||||
|
|
||||
LL | #[default]
|
||||
| ---------- `#[default]` used here
|
||||
|
|
@ -99,7 +99,7 @@ LL | Foo,
|
|||
|
|
||||
= note: only one `#[default]` attribute is needed
|
||||
help: try removing these
|
||||
--> $DIR/macros-nonfatal-errors.rs:76:5
|
||||
--> $DIR/macros-nonfatal-errors.rs:75:5
|
||||
|
|
||||
LL | #[default]
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -109,7 +109,7 @@ LL | #[default]
|
|||
| ^^^^^^^^^^
|
||||
|
||||
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 {},
|
||||
| ^^^
|
||||
|
|
@ -117,7 +117,7 @@ LL | Foo {},
|
|||
= help: consider a manual implementation of `Default`
|
||||
|
||||
error: default variant must be exhaustive
|
||||
--> $DIR/macros-nonfatal-errors.rs:94:5
|
||||
--> $DIR/macros-nonfatal-errors.rs:93:5
|
||||
|
|
||||
LL | #[non_exhaustive]
|
||||
| ----------------- declared `#[non_exhaustive]` here
|
||||
|
|
@ -127,37 +127,37 @@ LL | Foo,
|
|||
= help: consider a manual implementation of `Default`
|
||||
|
||||
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);
|
||||
| ^^^^^^^
|
||||
|
||||
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");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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);
|
||||
| ^^^^^^^
|
||||
|
||||
error: expected string literal
|
||||
--> $DIR/macros-nonfatal-errors.rs:105:10
|
||||
--> $DIR/macros-nonfatal-errors.rs:104:10
|
||||
|
|
||||
LL | env!(invalid);
|
||||
| ^^^^^^^
|
||||
|
||||
error: expected string literal
|
||||
--> $DIR/macros-nonfatal-errors.rs:106:10
|
||||
--> $DIR/macros-nonfatal-errors.rs:105:10
|
||||
|
|
||||
LL | env!(foo, abr, baz);
|
||||
| ^^^
|
||||
|
||||
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");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -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)
|
||||
|
||||
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);
|
||||
| ^^^^^^^
|
||||
|
|
@ -176,19 +176,19 @@ LL | format!("{}", invalid);
|
|||
| +++++
|
||||
|
||||
error: argument must be a string literal
|
||||
--> $DIR/macros-nonfatal-errors.rs:111:14
|
||||
--> $DIR/macros-nonfatal-errors.rs:110:14
|
||||
|
|
||||
LL | include!(invalid);
|
||||
| ^^^^^^^
|
||||
|
||||
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);
|
||||
| ^^^^^^^
|
||||
|
||||
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");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -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)
|
||||
|
||||
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);
|
||||
| ^^^^^^^
|
||||
|
||||
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");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -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)
|
||||
|
||||
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);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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);
|
||||
| ^^^^^^^^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue