summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0665.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0665.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0665.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md
new file mode 100644
index 000000000..ae54d6d15
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0665.md
@@ -0,0 +1,33 @@
+#### Note: this error code is no longer emitted by the compiler.
+
+The `Default` trait was derived on an enum.
+
+Erroneous code example:
+
+```compile_fail
+#[derive(Default)]
+enum Food {
+ Sweet,
+ Salty,
+}
+```
+
+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.
+
+If you still want to implement `Default` on your enum, you'll have to do it "by
+hand":
+
+```
+enum Food {
+ Sweet,
+ Salty,
+}
+
+impl Default for Food {
+ fn default() -> Food {
+ Food::Sweet
+ }
+}
+```