]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0665.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0665.md
1 #### Note: this error code is no longer emitted by the compiler.
2
3 The `Default` trait was derived on an enum.
4
5 Erroneous code example:
6
7 ```compile_fail
8 #[derive(Default)]
9 enum Food {
10     Sweet,
11     Salty,
12 }
13 ```
14
15 The `Default` cannot be derived on an enum for the simple reason that the
16 compiler doesn't know which value to pick by default whereas it can for a
17 struct as long as all its fields implement the `Default` trait as well.
18
19 If you still want to implement `Default` on your enum, you'll have to do it "by
20 hand":
21
22 ```
23 enum Food {
24     Sweet,
25     Salty,
26 }
27
28 impl Default for Food {
29     fn default() -> Food {
30         Food::Sweet
31     }
32 }
33 ```