about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-09 08:23:33 +0000
committerbors <bors@rust-lang.org>2020-09-09 08:23:33 +0000
commit3f5e617e3630ad61aa35637bbe0ab704eada5974 (patch)
tree8dc353f8c5ff5c71fc79c64117a617222a8d7fe8
parent0855263dcd329878b7183aa44b4ecdfdee229e6d (diff)
parent1d02f4fdcca2ca7b6dd487b505664a37cb1e9a8b (diff)
downloadrust-3f5e617e3630ad61aa35637bbe0ab704eada5974.tar.gz
rust-3f5e617e3630ad61aa35637bbe0ab704eada5974.zip
Auto merge of #76406 - GuillaumeGomez:create-e0774, r=pickfire,jyn514
Create E0774
-rw-r--r--compiler/rustc_error_codes/src/error_codes.rs1
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0774.md24
-rw-r--r--compiler/rustc_expand/src/expand.rs9
-rw-r--r--src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr5
-rw-r--r--src/test/ui/derives/deriving-non-type.stderr19
-rw-r--r--src/test/ui/feature-gate/issue-43106-gating-of-derive.stderr11
-rw-r--r--src/test/ui/issues/issue-36617.stderr3
-rw-r--r--src/test/ui/issues/issue-43023.stderr7
-rw-r--r--src/test/ui/issues/issue-49934-errors.stderr5
-rw-r--r--src/test/ui/macros/trace_faulty_macros.stderr3
-rw-r--r--src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr3
-rw-r--r--src/test/ui/proc-macro/attributes-on-modules-fail.stderr4
-rw-r--r--src/test/ui/proc-macro/macros-in-extern-derive.stderr3
-rw-r--r--src/test/ui/span/issue-43927-non-ADT-derive.stderr3
14 files changed, 69 insertions, 31 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs
index 789a1fc35a6..b0be1bf7e72 100644
--- a/compiler/rustc_error_codes/src/error_codes.rs
+++ b/compiler/rustc_error_codes/src/error_codes.rs
@@ -455,6 +455,7 @@ E0769: include_str!("./error_codes/E0769.md"),
 E0770: include_str!("./error_codes/E0770.md"),
 E0771: include_str!("./error_codes/E0771.md"),
 E0773: include_str!("./error_codes/E0773.md"),
+E0774: include_str!("./error_codes/E0774.md"),
 ;
 //  E0006, // merged with E0005
 //  E0008, // cannot bind by-move into a pattern guard
diff --git a/compiler/rustc_error_codes/src/error_codes/E0774.md b/compiler/rustc_error_codes/src/error_codes/E0774.md
new file mode 100644
index 00000000000..79793ba9d7d
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0774.md
@@ -0,0 +1,24 @@
+`derive` was applied on something which is not a struct, a union or an enum.
+
+Erroneous code example:
+
+```compile_fail,E0774
+trait Foo {
+    #[derive(Clone)] // error!
+    type Bar;
+}
+```
+
+As said above, the `derive` attribute is only allowed on structs, unions or
+enums:
+
+```
+#[derive(Clone)] // ok!
+struct Bar {
+    field: u32,
+}
+```
+
+You can find more information about `derive` in the [Rust Book].
+
+[Rust Book]: https://doc.rust-lang.org/book/appendix-03-derivable-traits.html
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 105f81c6e0f..ca6f7324ca4 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -529,9 +529,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
     fn error_derive_forbidden_on_non_adt(&self, derives: &[Path], item: &Annotatable) {
         let attr = self.cx.sess.find_by_name(item.attrs(), sym::derive);
         let span = attr.map_or(item.span(), |attr| attr.span);
-        let mut err = self
-            .cx
-            .struct_span_err(span, "`derive` may only be applied to structs, enums and unions");
+        let mut err = rustc_errors::struct_span_err!(
+            self.cx.sess,
+            span,
+            E0774,
+            "`derive` may only be applied to structs, enums and unions",
+        );
         if let Some(ast::Attribute { style: ast::AttrStyle::Inner, .. }) = attr {
             let trait_list = derives.iter().map(|t| pprust::path_to_string(t)).collect::<Vec<_>>();
             let suggestion = format!("#[derive({})]", trait_list.join(", "));
diff --git a/src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr b/src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr
index b3aa886cd49..e892d3f0863 100644
--- a/src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr
+++ b/src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr
@@ -1,10 +1,10 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/derive-on-trait-item-or-impl-item.rs:2:5
    |
 LL |     #[derive(Clone)]
    |     ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/derive-on-trait-item-or-impl-item.rs:10:5
    |
 LL |     #[derive(Clone)]
@@ -12,3 +12,4 @@ LL |     #[derive(Clone)]
 
 error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/derives/deriving-non-type.stderr b/src/test/ui/derives/deriving-non-type.stderr
index 563e76dc609..8c9daf4d4b3 100644
--- a/src/test/ui/derives/deriving-non-type.stderr
+++ b/src/test/ui/derives/deriving-non-type.stderr
@@ -1,52 +1,52 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:5:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:8:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:11:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:14:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:17:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:20:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:23:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:26:1
    |
 LL | #[derive(PartialEq)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/deriving-non-type.rs:29:1
    |
 LL | #[derive(PartialEq)]
@@ -54,3 +54,4 @@ LL | #[derive(PartialEq)]
 
 error: aborting due to 9 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-derive.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-derive.stderr
index db29a2bddd3..ffec76f409e 100644
--- a/src/test/ui/feature-gate/issue-43106-gating-of-derive.stderr
+++ b/src/test/ui/feature-gate/issue-43106-gating-of-derive.stderr
@@ -1,28 +1,28 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43106-gating-of-derive.rs:4:1
    |
 LL | #[derive(Debug)]
    | ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43106-gating-of-derive.rs:7:17
    |
 LL |     mod inner { #![derive(Debug)] }
    |                 ^^^^^^^^^^^^^^^^^ help: try an outer attribute: `#[derive(Debug)]`
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43106-gating-of-derive.rs:10:5
    |
 LL |     #[derive(Debug)]
    |     ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43106-gating-of-derive.rs:23:5
    |
 LL |     #[derive(Debug)]
    |     ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43106-gating-of-derive.rs:27:5
    |
 LL |     #[derive(Debug)]
@@ -30,3 +30,4 @@ LL |     #[derive(Debug)]
 
 error: aborting due to 5 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/issues/issue-36617.stderr b/src/test/ui/issues/issue-36617.stderr
index 98b41b07ea9..586dcf2cea6 100644
--- a/src/test/ui/issues/issue-36617.stderr
+++ b/src/test/ui/issues/issue-36617.stderr
@@ -1,4 +1,4 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-36617.rs:1:1
    |
 LL | #![derive(Copy)]
@@ -22,3 +22,4 @@ LL | #![derive(Copy)]
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/issues/issue-43023.stderr b/src/test/ui/issues/issue-43023.stderr
index 206a51645fe..f5f51cdcd48 100644
--- a/src/test/ui/issues/issue-43023.stderr
+++ b/src/test/ui/issues/issue-43023.stderr
@@ -1,16 +1,16 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43023.rs:4:5
    |
 LL |     #[derive(Debug)]
    |     ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43023.rs:11:5
    |
 LL |     #[derive(Debug)]
    |     ^^^^^^^^^^^^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43023.rs:16:5
    |
 LL |     #[derive(Debug)]
@@ -18,3 +18,4 @@ LL |     #[derive(Debug)]
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/issues/issue-49934-errors.stderr b/src/test/ui/issues/issue-49934-errors.stderr
index 8778d88d0eb..3befb38a208 100644
--- a/src/test/ui/issues/issue-49934-errors.stderr
+++ b/src/test/ui/issues/issue-49934-errors.stderr
@@ -1,4 +1,4 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-49934-errors.rs:1:8
    |
 LL | fn foo<#[derive(Debug)] T>() {
@@ -10,7 +10,7 @@ error: expected an inert attribute, found a derive macro
 LL | fn foo<#[derive(Debug)] T>() {
    |                 ^^^^^
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-49934-errors.rs:5:9
    |
 LL |         #[derive(Debug)]
@@ -24,3 +24,4 @@ LL |         #[derive(Debug)]
 
 error: aborting due to 4 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr
index aec9d1ab191..cecc942f470 100644
--- a/src/test/ui/macros/trace_faulty_macros.stderr
+++ b/src/test/ui/macros/trace_faulty_macros.stderr
@@ -60,7 +60,7 @@ LL |     let a = pat_macro!();
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/trace_faulty_macros.rs:42:1
    |
 LL | #[derive(Debug)]
@@ -79,3 +79,4 @@ LL |     let a = pat_macro!();
 
 error: aborting due to 4 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr b/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr
index e8f96178d10..c4532a375a7 100644
--- a/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr
+++ b/src/test/ui/malformed/issue-69341-malformed-derive-inert.stderr
@@ -4,7 +4,7 @@ error: traits in `#[derive(...)]` don't accept arguments
 LL |     #[derive(parse())]
    |                   ^^ help: remove the arguments
 
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-69341-malformed-derive-inert.rs:8:5
    |
 LL |     path: (),
@@ -24,3 +24,4 @@ LL |     #[derive(parse())]
 
 error: aborting due to 4 previous errors
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
index 97b2f22e161..7141a1b50b5 100644
--- a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
+++ b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr
@@ -1,4 +1,4 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/attributes-on-modules-fail.rs:16:1
    |
 LL | #[derive(Copy)]
@@ -64,5 +64,5 @@ LL | use m::X;
 
 error: aborting due to 7 previous errors
 
-Some errors have detailed explanations: E0412, E0658.
+Some errors have detailed explanations: E0412, E0658, E0774.
 For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/proc-macro/macros-in-extern-derive.stderr b/src/test/ui/proc-macro/macros-in-extern-derive.stderr
index e2afb7d34c1..6b737449209 100644
--- a/src/test/ui/proc-macro/macros-in-extern-derive.stderr
+++ b/src/test/ui/proc-macro/macros-in-extern-derive.stderr
@@ -1,4 +1,4 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/macros-in-extern-derive.rs:2:5
    |
 LL |     #[derive(Copy)]
@@ -6,3 +6,4 @@ LL |     #[derive(Copy)]
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0774`.
diff --git a/src/test/ui/span/issue-43927-non-ADT-derive.stderr b/src/test/ui/span/issue-43927-non-ADT-derive.stderr
index b68681c5297..b160a4e5877 100644
--- a/src/test/ui/span/issue-43927-non-ADT-derive.stderr
+++ b/src/test/ui/span/issue-43927-non-ADT-derive.stderr
@@ -1,4 +1,4 @@
-error: `derive` may only be applied to structs, enums and unions
+error[E0774]: `derive` may only be applied to structs, enums and unions
   --> $DIR/issue-43927-non-ADT-derive.rs:3:1
    |
 LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute!
@@ -54,3 +54,4 @@ LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute!
 
 error: aborting due to 7 previous errors
 
+For more information about this error, try `rustc --explain E0774`.