diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-12-21 02:43:09 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-12-21 19:14:58 +0000 |
| commit | 94812f1c8f455579a3a1c127c2bbac48fc7cecef (patch) | |
| tree | dd89eca57cb897363de7f2c26e0936c74486b922 /compiler/rustc_error_codes/src | |
| parent | d520b18316c71e1b61f2ed4df761f03149ff59e7 (diff) | |
| download | rust-94812f1c8f455579a3a1c127c2bbac48fc7cecef.tar.gz rust-94812f1c8f455579a3a1c127c2bbac48fc7cecef.zip | |
Use E0665 for missing `#[default]` error
Use orphaned error code for the same error it belonged to before.
```
error[E0665]: `#[derive(Default)]` on enum with no `#[default]`
--> $DIR/macros-nonfatal-errors.rs:42:10
|
LL | #[derive(Default)]
| ^^^^^^^
LL | / enum NoDeclaredDefault {
LL | | Foo,
LL | | Bar,
LL | | }
| |_- this enum needs a unit variant marked with `#[default]`
|
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
help: make this unit variant default by placing `#[default]` on it
|
LL | #[default] Foo,
| ~~~~~~~~~~~~~~
help: make this unit variant default by placing `#[default]` on it
|
LL | #[default] Bar,
| ~~~~~~~~~~~~~~
```
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0665.md | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md index d5fd2130840..caa94423377 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0665.md +++ b/compiler/rustc_error_codes/src/error_codes/E0665.md @@ -1,10 +1,9 @@ -#### Note: this error code is no longer emitted by the compiler. - -The `Default` trait was derived on an enum. +The `Default` trait was derived on an enum without specifying the default +variant. Erroneous code example: -```compile_fail +```compile_fail,E0665 #[derive(Default)] enum Food { Sweet, @@ -16,8 +15,8 @@ The `Default` cannot be derived on an enum for the simple reason that the compiler doesn't know which value to pick by default whereas it can for a struct as long as all its fields implement the `Default` trait as well. -For the case where the desired default variant has no data, you can annotate -it with `#[default]` to derive it: +For the case where the desired default variant has no payload, you can +annotate it with `#[default]` to derive it: ``` #[derive(Default)] @@ -28,8 +27,8 @@ enum Food { } ``` -In the case where the default variant does have data, you will have to -implement `Default` on your enum "by hand": +In the case where the default variant does have a payload, you will have to +implement `Default` on your enum manually: ``` enum Food { |
