]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0665.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0665.md
1 The `Default` trait was derived on an enum.
2
3 Erroneous code example:
4
5 ```compile_fail,E0665
6 #[derive(Default)]
7 enum Food {
8 Sweet,
9 Salty,
10 }
11 ```
12
13 The `Default` cannot be derived on an enum for the simple reason that the
14 compiler doesn't know which value to pick by default whereas it can for a
15 struct as long as all its fields implement the `Default` trait as well.
16
17 If you still want to implement `Default` on your enum, you'll have to do it "by
18 hand":
19
20 ```
21 enum Food {
22 Sweet,
23 Salty,
24 }
25
26 impl Default for Food {
27 fn default() -> Food {
28 Food::Sweet
29 }
30 }
31 ```