diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/derives | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/derives')
104 files changed, 2537 insertions, 0 deletions
diff --git a/src/test/ui/derives/auxiliary/derive-marker-tricky.rs b/src/test/ui/derives/auxiliary/derive-marker-tricky.rs new file mode 100644 index 000000000..70345351b --- /dev/null +++ b/src/test/ui/derives/auxiliary/derive-marker-tricky.rs @@ -0,0 +1,15 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::*; + +#[proc_macro_derive(NoMarker)] +pub fn f(input: TokenStream) -> TokenStream { + if input.to_string().contains("rustc_copy_clone_marker") { + panic!("found `#[rustc_copy_clone_marker]`"); + } + TokenStream::new() +} diff --git a/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.rs b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.rs new file mode 100644 index 000000000..15d068175 --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.rs @@ -0,0 +1,12 @@ +#![forbid(dead_code)] + +#[derive(Debug)] +pub struct Whatever { + pub field0: (), + field1: (), //~ ERROR fields `field1`, `field2`, `field3` and `field4` are never read + field2: (), + field3: (), + field4: (), +} + +fn main() {} diff --git a/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr new file mode 100644 index 000000000..baf34b46d --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr @@ -0,0 +1,24 @@ +error: fields `field1`, `field2`, `field3` and `field4` are never read + --> $DIR/clone-debug-dead-code-in-the-same-struct.rs:6:5 + | +LL | pub struct Whatever { + | -------- fields in this struct +LL | pub field0: (), +LL | field1: (), + | ^^^^^^ +LL | field2: (), + | ^^^^^^ +LL | field3: (), + | ^^^^^^ +LL | field4: (), + | ^^^^^^ + | +note: the lint level is defined here + --> $DIR/clone-debug-dead-code-in-the-same-struct.rs:1:11 + | +LL | #![forbid(dead_code)] + | ^^^^^^^^^ + = note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis + +error: aborting due to previous error + diff --git a/src/test/ui/derives/clone-debug-dead-code.rs b/src/test/ui/derives/clone-debug-dead-code.rs new file mode 100644 index 000000000..ab49260c0 --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code.rs @@ -0,0 +1,45 @@ +// Checks that derived implementations of Clone and Debug do not +// contribute to dead code analysis (issue #84647). + +#![forbid(dead_code)] + +struct A { f: () } +//~^ ERROR: field `f` is never read + +#[derive(Clone)] +struct B { f: () } +//~^ ERROR: field `f` is never read + +#[derive(Debug)] +struct C { f: () } +//~^ ERROR: field `f` is never read + +#[derive(Debug,Clone)] +struct D { f: () } +//~^ ERROR: field `f` is never read + +struct E { f: () } +//~^ ERROR: field `f` is never read +// Custom impl, still doesn't read f +impl Clone for E { + fn clone(&self) -> Self { + Self { f: () } + } +} + +struct F { f: () } +// Custom impl that actually reads f +impl Clone for F { + fn clone(&self) -> Self { + Self { f: self.f } + } +} + +fn main() { + let _ = A { f: () }; + let _ = B { f: () }; + let _ = C { f: () }; + let _ = D { f: () }; + let _ = E { f: () }; + let _ = F { f: () }; +} diff --git a/src/test/ui/derives/clone-debug-dead-code.stderr b/src/test/ui/derives/clone-debug-dead-code.stderr new file mode 100644 index 000000000..38be486e3 --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code.stderr @@ -0,0 +1,54 @@ +error: field `f` is never read + --> $DIR/clone-debug-dead-code.rs:6:12 + | +LL | struct A { f: () } + | - ^ + | | + | field in this struct + | +note: the lint level is defined here + --> $DIR/clone-debug-dead-code.rs:4:11 + | +LL | #![forbid(dead_code)] + | ^^^^^^^^^ + +error: field `f` is never read + --> $DIR/clone-debug-dead-code.rs:10:12 + | +LL | struct B { f: () } + | - ^ + | | + | field in this struct + | + = note: `B` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis + +error: field `f` is never read + --> $DIR/clone-debug-dead-code.rs:14:12 + | +LL | struct C { f: () } + | - ^ + | | + | field in this struct + | + = note: `C` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis + +error: field `f` is never read + --> $DIR/clone-debug-dead-code.rs:18:12 + | +LL | struct D { f: () } + | - ^ + | | + | field in this struct + | + = note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis + +error: field `f` is never read + --> $DIR/clone-debug-dead-code.rs:21:12 + | +LL | struct E { f: () } + | - ^ + | | + | field in this struct + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/derives/derive-Debug-use-ufcs-struct.rs b/src/test/ui/derives/derive-Debug-use-ufcs-struct.rs new file mode 100644 index 000000000..cb9dda841 --- /dev/null +++ b/src/test/ui/derives/derive-Debug-use-ufcs-struct.rs @@ -0,0 +1,40 @@ +// run-pass +#![allow(warnings)] + +#[derive(Debug)] +pub struct Bar { pub t: () } + +impl<T> Access for T {} +pub trait Access { + fn field(&self, _: impl Sized, _: impl Sized) { + panic!("got into Access::field"); + } + + fn finish(&self) -> Result<(), std::fmt::Error> { + panic!("got into Access::finish"); + } + + fn debug_struct(&self, _: impl Sized, _: impl Sized) { + panic!("got into Access::debug_struct"); + } +} + +impl<T> MutAccess for T {} +pub trait MutAccess { + fn field(&mut self, _: impl Sized, _: impl Sized) { + panic!("got into MutAccess::field"); + } + + fn finish(&mut self) -> Result<(), std::fmt::Error> { + panic!("got into MutAccess::finish"); + } + + fn debug_struct(&mut self, _: impl Sized, _: impl Sized) { + panic!("got into MutAccess::debug_struct"); + } +} + +fn main() { + let bar = Bar { t: () }; + assert_eq!("Bar { t: () }", format!("{:?}", bar)); +} diff --git a/src/test/ui/derives/derive-Debug-use-ufcs-tuple.rs b/src/test/ui/derives/derive-Debug-use-ufcs-tuple.rs new file mode 100644 index 000000000..5f786769f --- /dev/null +++ b/src/test/ui/derives/derive-Debug-use-ufcs-tuple.rs @@ -0,0 +1,32 @@ +// run-pass +#![allow(warnings)] + +#[derive(Debug)] +pub struct Foo<T>(pub T); + +use std::fmt; + +impl<T> Field for T {} +impl<T> Finish for T {} +impl Dt for &mut fmt::Formatter<'_> {} + +pub trait Field { + fn field(&self, _: impl Sized) { + panic!("got into field"); + } +} +pub trait Finish { + fn finish(&self) -> Result<(), std::fmt::Error> { + panic!("got into finish"); + } +} +pub trait Dt { + fn debug_tuple(&self, _: &str) { + panic!("got into debug_tuple"); + } +} + +fn main() { + let foo = Foo(()); + assert_eq!("Foo(())", format!("{:?}", foo)); +} diff --git a/src/test/ui/derives/derive-assoc-type-not-impl.rs b/src/test/ui/derives/derive-assoc-type-not-impl.rs new file mode 100644 index 000000000..0f642d63a --- /dev/null +++ b/src/test/ui/derives/derive-assoc-type-not-impl.rs @@ -0,0 +1,19 @@ +trait Foo { + type X; + fn method(&self) {} +} + +#[derive(Clone)] +struct Bar<T: Foo> { + x: T::X, +} + +struct NotClone; + +impl Foo for NotClone { + type X = i8; +} + +fn main() { + Bar::<NotClone> { x: 1 }.clone(); //~ ERROR +} diff --git a/src/test/ui/derives/derive-assoc-type-not-impl.stderr b/src/test/ui/derives/derive-assoc-type-not-impl.stderr new file mode 100644 index 000000000..c4fddcf5f --- /dev/null +++ b/src/test/ui/derives/derive-assoc-type-not-impl.stderr @@ -0,0 +1,34 @@ +error[E0599]: the method `clone` exists for struct `Bar<NotClone>`, but its trait bounds were not satisfied + --> $DIR/derive-assoc-type-not-impl.rs:18:30 + | +LL | struct Bar<T: Foo> { + | ------------------ + | | + | method `clone` not found for this struct + | doesn't satisfy `Bar<NotClone>: Clone` +... +LL | struct NotClone; + | --------------- doesn't satisfy `NotClone: Clone` +... +LL | Bar::<NotClone> { x: 1 }.clone(); + | ^^^^^ method cannot be called on `Bar<NotClone>` due to unsatisfied trait bounds + | +note: trait bound `NotClone: Clone` was not satisfied + --> $DIR/derive-assoc-type-not-impl.rs:6:10 + | +LL | #[derive(Clone)] + | ^^^^^ unsatisfied trait bound introduced in this `derive` macro + = note: the following trait bounds were not satisfied: + `NotClone: Clone` + which is required by `Bar<NotClone>: Clone` + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `clone`, perhaps you need to implement it: + candidate #1: `Clone` +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/derives/derive-deadlock.rs b/src/test/ui/derives/derive-deadlock.rs new file mode 100644 index 000000000..0137b1e5b --- /dev/null +++ b/src/test/ui/derives/derive-deadlock.rs @@ -0,0 +1,6 @@ +use std as derive; + +#[derive(Default)] //~ ERROR cannot determine resolution for the attribute macro `derive` +struct S; + +fn main() {} diff --git a/src/test/ui/derives/derive-deadlock.stderr b/src/test/ui/derives/derive-deadlock.stderr new file mode 100644 index 000000000..8d062491c --- /dev/null +++ b/src/test/ui/derives/derive-deadlock.stderr @@ -0,0 +1,10 @@ +error: cannot determine resolution for the attribute macro `derive` + --> $DIR/derive-deadlock.rs:3:3 + | +LL | #[derive(Default)] + | ^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: aborting due to previous error + diff --git a/src/test/ui/derives/derive-hygiene.rs b/src/test/ui/derives/derive-hygiene.rs new file mode 100644 index 000000000..4fa83c490 --- /dev/null +++ b/src/test/ui/derives/derive-hygiene.rs @@ -0,0 +1,121 @@ +// Make sure that built-in derives don't rely on the user not declaring certain +// names to work properly. + +// check-pass + +#![allow(nonstandard_style)] +#![feature(decl_macro)] + +use std::prelude::v1::test as inline; + +static f: () = (); +static cmp: () = (); +static other: () = (); +static state: () = (); +static __self_0_0: () = (); +static __self_1_0: () = (); +static __self_vi: () = (); +static __arg_1_0: () = (); +static debug_trait_builder: () = (); + +struct isize; +trait i16 {} + +trait MethodsInDerives: Sized { + fn debug_tuple(self) {} + fn debug_struct(self) {} + fn field(self) {} + fn finish(self) {} + fn clone(self) {} + fn cmp(self) {} + fn partial_cmp(self) {} + fn eq(self) {} + fn ne(self) {} + fn le(self) {} + fn lt(self) {} + fn ge(self) {} + fn gt(self) {} + fn hash(self) {} +} + +trait GenericAny<T, U> {} +impl<S, T, U> GenericAny<T, U> for S {} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +enum __H { V(i32), } + +#[repr(i16)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +enum W { A, B } + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] +struct X<A: GenericAny<A, self::X<i32>>> { + A: A, +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] +struct Y<B>(B) +where + B: From<B>; + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +enum Z<C> { + C(C), + B { C: C }, +} + +// Make sure that we aren't using `self::` in paths, since it doesn't work in +// non-module scopes. +const NON_MODULE: () = { + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum __H { V(i32), } + + #[repr(i16)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum W { A, B } + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] + struct X<A: Fn(A) -> self::X<i32>> { + A: A, + } + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] + struct Y<B>(B) + where + B: From<B>; + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum Z<C> { + C(C), + B { C: C }, + } +}; + +macro m() { + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum __H { V(i32), } + + #[repr(i16)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum W { A, B } + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] + struct X<A: GenericAny<A, self::X<i32>>> { + A: A, + } + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)] + struct Y<B>(B) + where + B: From<B>; + + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] + enum Z<C> { + C(C), + B { C: C }, + } +} + +m!(); + +fn main() {} diff --git a/src/test/ui/derives/derive-macro-const-default.rs b/src/test/ui/derives/derive-macro-const-default.rs new file mode 100644 index 000000000..ce80271d2 --- /dev/null +++ b/src/test/ui/derives/derive-macro-const-default.rs @@ -0,0 +1,11 @@ +// check-pass +#[derive(Clone, PartialEq, Debug)] +struct Example<T, const N: usize = 1usize>([T; N]); + +fn main() { + let a = Example([(); 16]); + let b = a.clone(); + if a != b { + let _c = format!("{:?}", a); + } +} diff --git a/src/test/ui/derives/derive-marker-tricky.rs b/src/test/ui/derives/derive-marker-tricky.rs new file mode 100644 index 000000000..730ea4714 --- /dev/null +++ b/src/test/ui/derives/derive-marker-tricky.rs @@ -0,0 +1,16 @@ +// Test that `#[rustc_copy_clone_marker]` is not injected when a user-defined derive shadows +// a built-in derive in non-trivial scope (e.g. in a nested module). + +// check-pass +// aux-build:derive-marker-tricky.rs + +extern crate derive_marker_tricky; + +mod m { + use derive_marker_tricky::NoMarker as Copy; + + #[derive(Copy)] + struct S; +} + +fn main() {} diff --git a/src/test/ui/derives/derive-multiple-with-packed.rs b/src/test/ui/derives/derive-multiple-with-packed.rs new file mode 100644 index 000000000..e762ee357 --- /dev/null +++ b/src/test/ui/derives/derive-multiple-with-packed.rs @@ -0,0 +1,10 @@ +// check-pass + +#[derive(Clone, Copy)] +#[derive(Debug)] // OK, even if `Copy` is in the different `#[derive]` +#[repr(packed)] +struct CacheRecordHeader { + field: u64, +} + +fn main() {} diff --git a/src/test/ui/derives/derive-on-trait-item-or-impl-item.rs b/src/test/ui/derives/derive-on-trait-item-or-impl-item.rs new file mode 100644 index 000000000..7e579ec22 --- /dev/null +++ b/src/test/ui/derives/derive-on-trait-item-or-impl-item.rs @@ -0,0 +1,15 @@ +trait Foo { + #[derive(Clone)] + //~^ ERROR `derive` may only be applied to `struct`s, `enum`s and `union`s + type Bar; +} + +struct Bar; + +impl Bar { + #[derive(Clone)] + //~^ ERROR `derive` may only be applied to `struct`s, `enum`s and `union`s + fn bar(&self) {} +} + +fn main() {} 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 new file mode 100644 index 000000000..1fd97bdd5 --- /dev/null +++ b/src/test/ui/derives/derive-on-trait-item-or-impl-item.stderr @@ -0,0 +1,21 @@ +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/derive-on-trait-item-or-impl-item.rs:2:5 + | +LL | #[derive(Clone)] + | ^^^^^^^^^^^^^^^^ not applicable here +LL | +LL | type Bar; + | --------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/derive-on-trait-item-or-impl-item.rs:10:5 + | +LL | #[derive(Clone)] + | ^^^^^^^^^^^^^^^^ not applicable here +LL | +LL | fn bar(&self) {} + | ---------------- not a `struct`, `enum` or `union` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/derives/derive-partial-ord.rs b/src/test/ui/derives/derive-partial-ord.rs new file mode 100644 index 000000000..9078a7ffa --- /dev/null +++ b/src/test/ui/derives/derive-partial-ord.rs @@ -0,0 +1,60 @@ +// Checks that in a derived implementation of PartialOrd the lt, le, ge, gt methods are consistent +// with partial_cmp. Also verifies that implementation is consistent with that for tuples. +// +// run-pass + +#[derive(PartialEq, PartialOrd)] +struct P(f64, f64); + +fn main() { + let values: &[f64] = &[1.0, 2.0, f64::NAN]; + for a in values { + for b in values { + for c in values { + for d in values { + // Check impl for a tuple. + check(&(*a, *b), &(*c, *d)); + + // Check derived impl. + check(&P(*a, *b), &P(*c, *d)); + + // Check that impls agree with each other. + assert_eq!( + PartialOrd::partial_cmp(&(*a, *b), &(*c, *d)), + PartialOrd::partial_cmp(&P(*a, *b), &P(*c, *d)), + ); + } + } + } + } +} + +fn check<T: PartialOrd>(a: &T, b: &T) { + use std::cmp::Ordering::*; + match PartialOrd::partial_cmp(a, b) { + None => { + assert!(!(a < b)); + assert!(!(a <= b)); + assert!(!(a > b)); + assert!(!(a >= b)); + } + Some(Equal) => { + assert!(!(a < b)); + assert!(a <= b); + assert!(!(a > b)); + assert!(a >= b); + } + Some(Less) => { + assert!(a < b); + assert!(a <= b); + assert!(!(a > b)); + assert!(!(a >= b)); + } + Some(Greater) => { + assert!(!(a < b)); + assert!(!(a <= b)); + assert!(a > b); + assert!(a >= b); + } + } +} diff --git a/src/test/ui/derives/derive-renamed.rs b/src/test/ui/derives/derive-renamed.rs new file mode 100644 index 000000000..d310e5806 --- /dev/null +++ b/src/test/ui/derives/derive-renamed.rs @@ -0,0 +1,11 @@ +// check-pass +// edition:2018 + +use derive as my_derive; + +#[my_derive(Debug)] +struct S; + +fn main() { + println!("{:?}", S); // OK +} diff --git a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.rs b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.rs new file mode 100644 index 000000000..b556d4424 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Clone)] +enum Enum { + A { + x: Error //~ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr new file mode 100644 index 000000000..7326324b0 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Clone` is not satisfied + --> $DIR/derives-span-Clone-enum-struct-variant.rs:9:6 + | +LL | #[derive(Clone)] + | ----- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ the trait `Clone` is not implemented for `Error` + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Clone-enum.rs b/src/test/ui/derives/derives-span-Clone-enum.rs new file mode 100644 index 000000000..9bb4f486c --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-enum.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Clone)] +enum Enum { + A( + Error //~ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Clone-enum.stderr b/src/test/ui/derives/derives-span-Clone-enum.stderr new file mode 100644 index 000000000..229a4f7d9 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-enum.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Clone` is not satisfied + --> $DIR/derives-span-Clone-enum.rs:9:6 + | +LL | #[derive(Clone)] + | ----- in this derive macro expansion +... +LL | Error + | ^^^^^ the trait `Clone` is not implemented for `Error` + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Clone-struct.rs b/src/test/ui/derives/derives-span-Clone-struct.rs new file mode 100644 index 000000000..f151636f8 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Clone)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Clone-struct.stderr b/src/test/ui/derives/derives-span-Clone-struct.stderr new file mode 100644 index 000000000..96bad9eda --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Clone` is not satisfied + --> $DIR/derives-span-Clone-struct.rs:8:5 + | +LL | #[derive(Clone)] + | ----- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ the trait `Clone` is not implemented for `Error` + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Clone-tuple-struct.rs b/src/test/ui/derives/derives-span-Clone-tuple-struct.rs new file mode 100644 index 000000000..7a6288532 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Clone)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr new file mode 100644 index 000000000..b61341e57 --- /dev/null +++ b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Clone` is not satisfied + --> $DIR/derives-span-Clone-tuple-struct.rs:8:5 + | +LL | #[derive(Clone)] + | ----- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ the trait `Clone` is not implemented for `Error` + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.rs b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.rs new file mode 100644 index 000000000..949597bc8 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Debug)] +enum Enum { + A { + x: Error //~ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr new file mode 100644 index 000000000..58a64a4f5 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Error` doesn't implement `Debug` + --> $DIR/derives-span-Debug-enum-struct-variant.rs:9:6 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ `Error` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `Error` + = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Debug-enum.rs b/src/test/ui/derives/derives-span-Debug-enum.rs new file mode 100644 index 000000000..b2a39708c --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-enum.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Debug)] +enum Enum { + A( + Error //~ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Debug-enum.stderr b/src/test/ui/derives/derives-span-Debug-enum.stderr new file mode 100644 index 000000000..e9bb5f960 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-enum.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Error` doesn't implement `Debug` + --> $DIR/derives-span-Debug-enum.rs:9:6 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +... +LL | Error + | ^^^^^ `Error` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `Error` + = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Debug-struct.rs b/src/test/ui/derives/derives-span-Debug-struct.rs new file mode 100644 index 000000000..cf91c9436 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Debug)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Debug-struct.stderr b/src/test/ui/derives/derives-span-Debug-struct.stderr new file mode 100644 index 000000000..0a117c060 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-struct.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Error` doesn't implement `Debug` + --> $DIR/derives-span-Debug-struct.rs:8:5 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ `Error` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `Error` + = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Debug-tuple-struct.rs b/src/test/ui/derives/derives-span-Debug-tuple-struct.rs new file mode 100644 index 000000000..cea973c91 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Debug)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr new file mode 100644 index 000000000..f2e90a418 --- /dev/null +++ b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Error` doesn't implement `Debug` + --> $DIR/derives-span-Debug-tuple-struct.rs:8:5 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ `Error` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `Error` + = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Default-struct.rs b/src/test/ui/derives/derives-span-Default-struct.rs new file mode 100644 index 000000000..71fd5829e --- /dev/null +++ b/src/test/ui/derives/derives-span-Default-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Default)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Default-struct.stderr b/src/test/ui/derives/derives-span-Default-struct.stderr new file mode 100644 index 000000000..d4affd535 --- /dev/null +++ b/src/test/ui/derives/derives-span-Default-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Default` is not satisfied + --> $DIR/derives-span-Default-struct.rs:8:5 + | +LL | #[derive(Default)] + | ------- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ the trait `Default` is not implemented for `Error` + | + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Default-tuple-struct.rs b/src/test/ui/derives/derives-span-Default-tuple-struct.rs new file mode 100644 index 000000000..463f7d230 --- /dev/null +++ b/src/test/ui/derives/derives-span-Default-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Default)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Default-tuple-struct.stderr b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr new file mode 100644 index 000000000..129351f59 --- /dev/null +++ b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Default` is not satisfied + --> $DIR/derives-span-Default-tuple-struct.rs:8:5 + | +LL | #[derive(Default)] + | ------- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ the trait `Default` is not implemented for `Error` + | + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.rs b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.rs new file mode 100644 index 000000000..d2dab8687 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(Eq,PartialEq)] +enum Enum { + A { + x: Error //~ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr new file mode 100644 index 000000000..e3fb234b9 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr @@ -0,0 +1,23 @@ +error[E0277]: the trait bound `Error: Eq` is not satisfied + --> $DIR/derives-span-Eq-enum-struct-variant.rs:9:6 + | +LL | #[derive(Eq,PartialEq)] + | -- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ the trait `Eq` is not implemented for `Error` + | +note: required by a bound in `AssertParamIsEq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub struct AssertParamIsEq<T: Eq + ?Sized> { + | ^^ required by this bound in `AssertParamIsEq` + = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Eq-enum.rs b/src/test/ui/derives/derives-span-Eq-enum.rs new file mode 100644 index 000000000..c6c0d4321 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-enum.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(Eq,PartialEq)] +enum Enum { + A( + Error //~ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Eq-enum.stderr b/src/test/ui/derives/derives-span-Eq-enum.stderr new file mode 100644 index 000000000..4e10c3f69 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-enum.stderr @@ -0,0 +1,23 @@ +error[E0277]: the trait bound `Error: Eq` is not satisfied + --> $DIR/derives-span-Eq-enum.rs:9:6 + | +LL | #[derive(Eq,PartialEq)] + | -- in this derive macro expansion +... +LL | Error + | ^^^^^ the trait `Eq` is not implemented for `Error` + | +note: required by a bound in `AssertParamIsEq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub struct AssertParamIsEq<T: Eq + ?Sized> { + | ^^ required by this bound in `AssertParamIsEq` + = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Eq-struct.rs b/src/test/ui/derives/derives-span-Eq-struct.rs new file mode 100644 index 000000000..df3100398 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(Eq,PartialEq)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Eq-struct.stderr b/src/test/ui/derives/derives-span-Eq-struct.stderr new file mode 100644 index 000000000..bfdab052a --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-struct.stderr @@ -0,0 +1,23 @@ +error[E0277]: the trait bound `Error: Eq` is not satisfied + --> $DIR/derives-span-Eq-struct.rs:8:5 + | +LL | #[derive(Eq,PartialEq)] + | -- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ the trait `Eq` is not implemented for `Error` + | +note: required by a bound in `AssertParamIsEq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub struct AssertParamIsEq<T: Eq + ?Sized> { + | ^^ required by this bound in `AssertParamIsEq` + = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Eq-tuple-struct.rs b/src/test/ui/derives/derives-span-Eq-tuple-struct.rs new file mode 100644 index 000000000..abf6526b9 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(Eq,PartialEq)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr new file mode 100644 index 000000000..26b8be343 --- /dev/null +++ b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr @@ -0,0 +1,23 @@ +error[E0277]: the trait bound `Error: Eq` is not satisfied + --> $DIR/derives-span-Eq-tuple-struct.rs:8:5 + | +LL | #[derive(Eq,PartialEq)] + | -- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ the trait `Eq` is not implemented for `Error` + | +note: required by a bound in `AssertParamIsEq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub struct AssertParamIsEq<T: Eq + ?Sized> { + | ^^ required by this bound in `AssertParamIsEq` + = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.rs b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.rs new file mode 100644 index 000000000..3018a7b6d --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Hash)] +enum Enum { + A { + x: Error //~ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr new file mode 100644 index 000000000..fe5e0e96a --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Hash` is not satisfied + --> $DIR/derives-span-Hash-enum-struct-variant.rs:9:6 + | +LL | #[derive(Hash)] + | ---- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ the trait `Hash` is not implemented for `Error` + | + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Hash-enum.rs b/src/test/ui/derives/derives-span-Hash-enum.rs new file mode 100644 index 000000000..8ce7df18f --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-enum.rs @@ -0,0 +1,12 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +struct Error; + +#[derive(Hash)] +enum Enum { + A( + Error //~ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Hash-enum.stderr b/src/test/ui/derives/derives-span-Hash-enum.stderr new file mode 100644 index 000000000..99785b87c --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-enum.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Hash` is not satisfied + --> $DIR/derives-span-Hash-enum.rs:8:6 + | +LL | #[derive(Hash)] + | ---- in this derive macro expansion +... +LL | Error + | ^^^^^ the trait `Hash` is not implemented for `Error` + | + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Hash-struct.rs b/src/test/ui/derives/derives-span-Hash-struct.rs new file mode 100644 index 000000000..fa5e2af6b --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Hash)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Hash-struct.stderr b/src/test/ui/derives/derives-span-Hash-struct.stderr new file mode 100644 index 000000000..4db83dd13 --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Hash` is not satisfied + --> $DIR/derives-span-Hash-struct.rs:8:5 + | +LL | #[derive(Hash)] + | ---- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ the trait `Hash` is not implemented for `Error` + | + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.rs b/src/test/ui/derives/derives-span-Hash-tuple-struct.rs new file mode 100644 index 000000000..3822bce14 --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(Hash)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr new file mode 100644 index 000000000..8660c97e6 --- /dev/null +++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Hash` is not satisfied + --> $DIR/derives-span-Hash-tuple-struct.rs:8:5 + | +LL | #[derive(Hash)] + | ---- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ the trait `Hash` is not implemented for `Error` + | + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.rs b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.rs new file mode 100644 index 000000000..62355cc2d --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(Eq,PartialOrd,PartialEq)] +struct Error; + +#[derive(Ord,Eq,PartialOrd,PartialEq)] +enum Enum { + A { + x: Error //~ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr new file mode 100644 index 000000000..6e48332c2 --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Ord` is not satisfied + --> $DIR/derives-span-Ord-enum-struct-variant.rs:9:6 + | +LL | #[derive(Ord,Eq,PartialOrd,PartialEq)] + | --- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ the trait `Ord` is not implemented for `Error` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Ord-enum.rs b/src/test/ui/derives/derives-span-Ord-enum.rs new file mode 100644 index 000000000..72738931d --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-enum.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(Eq,PartialOrd,PartialEq)] +struct Error; + +#[derive(Ord,Eq,PartialOrd,PartialEq)] +enum Enum { + A( + Error //~ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Ord-enum.stderr b/src/test/ui/derives/derives-span-Ord-enum.stderr new file mode 100644 index 000000000..b05cf0a05 --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-enum.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Ord` is not satisfied + --> $DIR/derives-span-Ord-enum.rs:9:6 + | +LL | #[derive(Ord,Eq,PartialOrd,PartialEq)] + | --- in this derive macro expansion +... +LL | Error + | ^^^^^ the trait `Ord` is not implemented for `Error` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Ord-struct.rs b/src/test/ui/derives/derives-span-Ord-struct.rs new file mode 100644 index 000000000..53d4c2c22 --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(Eq,PartialOrd,PartialEq)] +struct Error; + +#[derive(Ord,Eq,PartialOrd,PartialEq)] +struct Struct { + x: Error //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Ord-struct.stderr b/src/test/ui/derives/derives-span-Ord-struct.stderr new file mode 100644 index 000000000..c4def34a8 --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Ord` is not satisfied + --> $DIR/derives-span-Ord-struct.rs:8:5 + | +LL | #[derive(Ord,Eq,PartialOrd,PartialEq)] + | --- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ the trait `Ord` is not implemented for `Error` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-Ord-tuple-struct.rs b/src/test/ui/derives/derives-span-Ord-tuple-struct.rs new file mode 100644 index 000000000..4e09c2709 --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(Eq,PartialOrd,PartialEq)] +struct Error; + +#[derive(Ord,Eq,PartialOrd,PartialEq)] +struct Struct( + Error //~ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr new file mode 100644 index 000000000..a3b288d0f --- /dev/null +++ b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `Error: Ord` is not satisfied + --> $DIR/derives-span-Ord-tuple-struct.rs:8:5 + | +LL | #[derive(Ord,Eq,PartialOrd,PartialEq)] + | --- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ the trait `Ord` is not implemented for `Error` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.rs b/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.rs new file mode 100644 index 000000000..d66faa086 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.rs @@ -0,0 +1,14 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(PartialEq)] +enum Enum { + A { + x: Error //~ ERROR +//~^ ERROR + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr new file mode 100644 index 000000000..f655600b7 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr @@ -0,0 +1,43 @@ +error[E0369]: binary operation `==` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-enum-struct-variant.rs:9:6 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-enum-struct-variant.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0369]: binary operation `!=` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-enum-struct-variant.rs:9:6 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-enum-struct-variant.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/derives/derives-span-PartialEq-enum.rs b/src/test/ui/derives/derives-span-PartialEq-enum.rs new file mode 100644 index 000000000..66edf460b --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-enum.rs @@ -0,0 +1,14 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(PartialEq)] +enum Enum { + A( + Error //~ ERROR +//~^ ERROR + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialEq-enum.stderr b/src/test/ui/derives/derives-span-PartialEq-enum.stderr new file mode 100644 index 000000000..ce4b00bfb --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-enum.stderr @@ -0,0 +1,43 @@ +error[E0369]: binary operation `==` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-enum.rs:9:6 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +... +LL | Error + | ^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-enum.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0369]: binary operation `!=` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-enum.rs:9:6 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +... +LL | Error + | ^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-enum.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/derives/derives-span-PartialEq-struct.rs b/src/test/ui/derives/derives-span-PartialEq-struct.rs new file mode 100644 index 000000000..ce5c67af7 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-struct.rs @@ -0,0 +1,12 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(PartialEq)] +struct Struct { + x: Error //~ ERROR +//~^ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialEq-struct.stderr b/src/test/ui/derives/derives-span-PartialEq-struct.stderr new file mode 100644 index 000000000..c5c8f255f --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-struct.stderr @@ -0,0 +1,43 @@ +error[E0369]: binary operation `==` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-struct.rs:8:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-struct.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0369]: binary operation `!=` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-struct.rs:8:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-struct.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/derives/derives-span-PartialEq-tuple-struct.rs b/src/test/ui/derives/derives-span-PartialEq-tuple-struct.rs new file mode 100644 index 000000000..eaa628311 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-tuple-struct.rs @@ -0,0 +1,12 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + + +struct Error; + +#[derive(PartialEq)] +struct Struct( + Error //~ ERROR +//~^ ERROR +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialEq-tuple-struct.stderr b/src/test/ui/derives/derives-span-PartialEq-tuple-struct.stderr new file mode 100644 index 000000000..f5d609cb3 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialEq-tuple-struct.stderr @@ -0,0 +1,43 @@ +error[E0369]: binary operation `==` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-tuple-struct.rs:8:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-tuple-struct.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0369]: binary operation `!=` cannot be applied to type `Error` + --> $DIR/derives-span-PartialEq-tuple-struct.rs:8:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `Error` + --> $DIR/derives-span-PartialEq-tuple-struct.rs:4:1 + | +LL | struct Error; + | ^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.rs b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.rs new file mode 100644 index 000000000..a769c1376 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(PartialOrd,PartialEq)] +enum Enum { + A { + x: Error //~ ERROR can't compare `Error` with `Error` + } +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr new file mode 100644 index 000000000..2d19aaf68 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr @@ -0,0 +1,19 @@ +error[E0277]: can't compare `Error` with `Error` + --> $DIR/derives-span-PartialOrd-enum-struct-variant.rs:9:6 + | +LL | #[derive(PartialOrd,PartialEq)] + | ---------- in this derive macro expansion +... +LL | x: Error + | ^^^^^^^^ no implementation for `Error < Error` and `Error > Error` + | + = help: the trait `PartialOrd` is not implemented for `Error` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum.rs b/src/test/ui/derives/derives-span-PartialOrd-enum.rs new file mode 100644 index 000000000..4f0d794e4 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-enum.rs @@ -0,0 +1,13 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(PartialOrd,PartialEq)] +enum Enum { + A( + Error //~ ERROR can't compare `Error` with `Error` + ) +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr new file mode 100644 index 000000000..dfbb8060f --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr @@ -0,0 +1,19 @@ +error[E0277]: can't compare `Error` with `Error` + --> $DIR/derives-span-PartialOrd-enum.rs:9:6 + | +LL | #[derive(PartialOrd,PartialEq)] + | ---------- in this derive macro expansion +... +LL | Error + | ^^^^^ no implementation for `Error < Error` and `Error > Error` + | + = help: the trait `PartialOrd` is not implemented for `Error` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-PartialOrd-struct.rs b/src/test/ui/derives/derives-span-PartialOrd-struct.rs new file mode 100644 index 000000000..da857c674 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(PartialOrd,PartialEq)] +struct Struct { + x: Error //~ ERROR can't compare `Error` with `Error` +} + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialOrd-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr new file mode 100644 index 000000000..ba63d86e8 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr @@ -0,0 +1,19 @@ +error[E0277]: can't compare `Error` with `Error` + --> $DIR/derives-span-PartialOrd-struct.rs:8:5 + | +LL | #[derive(PartialOrd,PartialEq)] + | ---------- in this derive macro expansion +LL | struct Struct { +LL | x: Error + | ^^^^^^^^ no implementation for `Error < Error` and `Error > Error` + | + = help: the trait `PartialOrd` is not implemented for `Error` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.rs b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.rs new file mode 100644 index 000000000..61d507670 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.rs @@ -0,0 +1,11 @@ +// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' + +#[derive(PartialEq)] +struct Error; + +#[derive(PartialOrd,PartialEq)] +struct Struct( + Error //~ ERROR can't compare `Error` with `Error` +); + +fn main() {} diff --git a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr new file mode 100644 index 000000000..7686ed806 --- /dev/null +++ b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr @@ -0,0 +1,19 @@ +error[E0277]: can't compare `Error` with `Error` + --> $DIR/derives-span-PartialOrd-tuple-struct.rs:8:5 + | +LL | #[derive(PartialOrd,PartialEq)] + | ---------- in this derive macro expansion +LL | struct Struct( +LL | Error + | ^^^^^ no implementation for `Error < Error` and `Error > Error` + | + = help: the trait `PartialOrd` is not implemented for `Error` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/deriving-bounds.rs b/src/test/ui/derives/deriving-bounds.rs new file mode 100644 index 000000000..95d440420 --- /dev/null +++ b/src/test/ui/derives/deriving-bounds.rs @@ -0,0 +1,11 @@ +#[derive(Send)] +//~^ ERROR cannot find derive macro `Send` in this scope +//~| ERROR cannot find derive macro `Send` in this scope +struct Test; + +#[derive(Sync)] +//~^ ERROR cannot find derive macro `Sync` in this scope +//~| ERROR cannot find derive macro `Sync` in this scope +struct Test1; + +pub fn main() {} diff --git a/src/test/ui/derives/deriving-bounds.stderr b/src/test/ui/derives/deriving-bounds.stderr new file mode 100644 index 000000000..74ca37287 --- /dev/null +++ b/src/test/ui/derives/deriving-bounds.stderr @@ -0,0 +1,50 @@ +error: cannot find derive macro `Sync` in this scope + --> $DIR/deriving-bounds.rs:6:10 + | +LL | #[derive(Sync)] + | ^^^^ + | +note: unsafe traits like `Sync` should be implemented explicitly + --> $DIR/deriving-bounds.rs:6:10 + | +LL | #[derive(Sync)] + | ^^^^ + +error: cannot find derive macro `Sync` in this scope + --> $DIR/deriving-bounds.rs:6:10 + | +LL | #[derive(Sync)] + | ^^^^ + | +note: unsafe traits like `Sync` should be implemented explicitly + --> $DIR/deriving-bounds.rs:6:10 + | +LL | #[derive(Sync)] + | ^^^^ + +error: cannot find derive macro `Send` in this scope + --> $DIR/deriving-bounds.rs:1:10 + | +LL | #[derive(Send)] + | ^^^^ + | +note: unsafe traits like `Send` should be implemented explicitly + --> $DIR/deriving-bounds.rs:1:10 + | +LL | #[derive(Send)] + | ^^^^ + +error: cannot find derive macro `Send` in this scope + --> $DIR/deriving-bounds.rs:1:10 + | +LL | #[derive(Send)] + | ^^^^ + | +note: unsafe traits like `Send` should be implemented explicitly + --> $DIR/deriving-bounds.rs:1:10 + | +LL | #[derive(Send)] + | ^^^^ + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/derives/deriving-copyclone.rs b/src/test/ui/derives/deriving-copyclone.rs new file mode 100644 index 000000000..06b3157a7 --- /dev/null +++ b/src/test/ui/derives/deriving-copyclone.rs @@ -0,0 +1,37 @@ +// this will get a no-op Clone impl +#[derive(Copy, Clone)] +struct A { + a: i32, + b: i64 +} + +// this will get a deep Clone impl +#[derive(Copy, Clone)] +struct B<T> { + a: i32, + b: T +} + +struct C; // not Copy or Clone +#[derive(Clone)] struct D; // Clone but not Copy + +fn is_copy<T: Copy>(_: T) {} +fn is_clone<T: Clone>(_: T) {} + +fn main() { + // A can be copied and cloned + is_copy(A { a: 1, b: 2 }); + is_clone(A { a: 1, b: 2 }); + + // B<i32> can be copied and cloned + is_copy(B { a: 1, b: 2 }); + is_clone(B { a: 1, b: 2 }); + + // B<C> cannot be copied or cloned + is_copy(B { a: 1, b: C }); //~ ERROR Copy + is_clone(B { a: 1, b: C }); //~ ERROR Clone + + // B<D> can be cloned but not copied + is_copy(B { a: 1, b: D }); //~ ERROR Copy + is_clone(B { a: 1, b: D }); +} diff --git a/src/test/ui/derives/deriving-copyclone.stderr b/src/test/ui/derives/deriving-copyclone.stderr new file mode 100644 index 000000000..13097edf0 --- /dev/null +++ b/src/test/ui/derives/deriving-copyclone.stderr @@ -0,0 +1,75 @@ +error[E0277]: the trait bound `B<C>: Copy` is not satisfied + --> $DIR/deriving-copyclone.rs:31:13 + | +LL | is_copy(B { a: 1, b: C }); + | ------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Copy` + | | + | required by a bound introduced by this call + | +note: required because of the requirements on the impl of `Copy` for `B<C>` + --> $DIR/deriving-copyclone.rs:9:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ +note: required by a bound in `is_copy` + --> $DIR/deriving-copyclone.rs:18:15 + | +LL | fn is_copy<T: Copy>(_: T) {} + | ^^^^ required by this bound in `is_copy` + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider borrowing here + | +LL | is_copy(&B { a: 1, b: C }); + | + + +error[E0277]: the trait bound `B<C>: Clone` is not satisfied + --> $DIR/deriving-copyclone.rs:32:14 + | +LL | is_clone(B { a: 1, b: C }); + | -------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone` + | | + | required by a bound introduced by this call + | +note: required because of the requirements on the impl of `Clone` for `B<C>` + --> $DIR/deriving-copyclone.rs:9:16 + | +LL | #[derive(Copy, Clone)] + | ^^^^^ +note: required by a bound in `is_clone` + --> $DIR/deriving-copyclone.rs:19:16 + | +LL | fn is_clone<T: Clone>(_: T) {} + | ^^^^^ required by this bound in `is_clone` + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider borrowing here + | +LL | is_clone(&B { a: 1, b: C }); + | + + +error[E0277]: the trait bound `B<D>: Copy` is not satisfied + --> $DIR/deriving-copyclone.rs:35:13 + | +LL | is_copy(B { a: 1, b: D }); + | ------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Copy` + | | + | required by a bound introduced by this call + | +note: required because of the requirements on the impl of `Copy` for `B<D>` + --> $DIR/deriving-copyclone.rs:9:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ +note: required by a bound in `is_copy` + --> $DIR/deriving-copyclone.rs:18:15 + | +LL | fn is_copy<T: Copy>(_: T) {} + | ^^^^ required by this bound in `is_copy` + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider borrowing here + | +LL | is_copy(&B { a: 1, b: D }); + | + + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/deriving-meta-empty-trait-list.rs b/src/test/ui/derives/deriving-meta-empty-trait-list.rs new file mode 100644 index 000000000..0306ce717 --- /dev/null +++ b/src/test/ui/derives/deriving-meta-empty-trait-list.rs @@ -0,0 +1,8 @@ +// check-pass + +#![deny(unused)] + +#[derive()] // OK +struct _Bar; + +pub fn main() {} diff --git a/src/test/ui/derives/deriving-meta-unknown-trait.rs b/src/test/ui/derives/deriving-meta-unknown-trait.rs new file mode 100644 index 000000000..6463a7664 --- /dev/null +++ b/src/test/ui/derives/deriving-meta-unknown-trait.rs @@ -0,0 +1,6 @@ +#[derive(Eqr)] +//~^ ERROR cannot find derive macro `Eqr` in this scope +//~| ERROR cannot find derive macro `Eqr` in this scope +struct Foo; + +pub fn main() {} diff --git a/src/test/ui/derives/deriving-meta-unknown-trait.stderr b/src/test/ui/derives/deriving-meta-unknown-trait.stderr new file mode 100644 index 000000000..f3ff95a85 --- /dev/null +++ b/src/test/ui/derives/deriving-meta-unknown-trait.stderr @@ -0,0 +1,24 @@ +error: cannot find derive macro `Eqr` in this scope + --> $DIR/deriving-meta-unknown-trait.rs:1:10 + | +LL | #[derive(Eqr)] + | ^^^ help: a derive macro with a similar name exists: `Eq` + | + ::: $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub macro Eq($item:item) { + | ------------ similarly named derive macro `Eq` defined here + +error: cannot find derive macro `Eqr` in this scope + --> $DIR/deriving-meta-unknown-trait.rs:1:10 + | +LL | #[derive(Eqr)] + | ^^^ help: a derive macro with a similar name exists: `Eq` + | + ::: $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub macro Eq($item:item) { + | ------------ similarly named derive macro `Eq` defined here + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/derives/deriving-no-inner-impl-error-message.rs b/src/test/ui/derives/deriving-no-inner-impl-error-message.rs new file mode 100644 index 000000000..39e41a59e --- /dev/null +++ b/src/test/ui/derives/deriving-no-inner-impl-error-message.rs @@ -0,0 +1,15 @@ +struct NoCloneOrEq; + +#[derive(PartialEq)] +struct E { + x: NoCloneOrEq //~ ERROR binary operation `==` cannot be applied to type `NoCloneOrEq` + //~^ ERROR binary operation `!=` cannot be applied to type `NoCloneOrEq` +} +#[derive(Clone)] +struct C { + x: NoCloneOrEq + //~^ ERROR `NoCloneOrEq: Clone` is not satisfied +} + + +fn main() {} diff --git a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr new file mode 100644 index 000000000..7875f0723 --- /dev/null +++ b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr @@ -0,0 +1,59 @@ +error[E0369]: binary operation `==` cannot be applied to type `NoCloneOrEq` + --> $DIR/deriving-no-inner-impl-error-message.rs:5:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct E { +LL | x: NoCloneOrEq + | ^^^^^^^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `NoCloneOrEq` + --> $DIR/deriving-no-inner-impl-error-message.rs:1:1 + | +LL | struct NoCloneOrEq; + | ^^^^^^^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoCloneOrEq` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0369]: binary operation `!=` cannot be applied to type `NoCloneOrEq` + --> $DIR/deriving-no-inner-impl-error-message.rs:5:5 + | +LL | #[derive(PartialEq)] + | --------- in this derive macro expansion +LL | struct E { +LL | x: NoCloneOrEq + | ^^^^^^^^^^^^^^ + | +note: an implementation of `PartialEq<_>` might be missing for `NoCloneOrEq` + --> $DIR/deriving-no-inner-impl-error-message.rs:1:1 + | +LL | struct NoCloneOrEq; + | ^^^^^^^^^^^^^^^^^^ must implement `PartialEq<_>` + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoCloneOrEq` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error[E0277]: the trait bound `NoCloneOrEq: Clone` is not satisfied + --> $DIR/deriving-no-inner-impl-error-message.rs:10:5 + | +LL | #[derive(Clone)] + | ----- in this derive macro expansion +LL | struct C { +LL | x: NoCloneOrEq + | ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq` + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoCloneOrEq` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0369. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/derives/deriving-non-type.rs b/src/test/ui/derives/deriving-non-type.rs new file mode 100644 index 000000000..9afffa900 --- /dev/null +++ b/src/test/ui/derives/deriving-non-type.rs @@ -0,0 +1,30 @@ +#![allow(dead_code)] + +struct S; + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +trait T { } + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +impl S { } + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +impl T for S { } + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +static s: usize = 0; + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +const c: usize = 0; + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +mod m { } + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +extern "C" { } + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +type A = usize; + +#[derive(PartialEq)] //~ ERROR: `derive` may only be applied to `struct`s, `enum`s and `union`s +fn main() { } diff --git a/src/test/ui/derives/deriving-non-type.stderr b/src/test/ui/derives/deriving-non-type.stderr new file mode 100644 index 000000000..ef7ef54d1 --- /dev/null +++ b/src/test/ui/derives/deriving-non-type.stderr @@ -0,0 +1,75 @@ +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:5:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | trait T { } + | ----------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:8:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | impl S { } + | ---------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:11:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | impl T for S { } + | ---------------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:14:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | static s: usize = 0; + | -------------------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:17:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | const c: usize = 0; + | ------------------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:20:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | mod m { } + | --------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:23:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | extern "C" { } + | -------------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:26:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | type A = usize; + | --------------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/deriving-non-type.rs:29:1 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^ not applicable here +LL | fn main() { } + | ------------- not a `struct`, `enum` or `union` + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/derives/deriving-primitive.rs b/src/test/ui/derives/deriving-primitive.rs new file mode 100644 index 000000000..1173eca64 --- /dev/null +++ b/src/test/ui/derives/deriving-primitive.rs @@ -0,0 +1,5 @@ +#[derive(FromPrimitive)] //~ ERROR cannot find derive macro `FromPrimitive` in this scope + //~| ERROR cannot find derive macro `FromPrimitive` in this scope +enum Foo {} + +fn main() {} diff --git a/src/test/ui/derives/deriving-primitive.stderr b/src/test/ui/derives/deriving-primitive.stderr new file mode 100644 index 000000000..ca64c9ee7 --- /dev/null +++ b/src/test/ui/derives/deriving-primitive.stderr @@ -0,0 +1,14 @@ +error: cannot find derive macro `FromPrimitive` in this scope + --> $DIR/deriving-primitive.rs:1:10 + | +LL | #[derive(FromPrimitive)] + | ^^^^^^^^^^^^^ + +error: cannot find derive macro `FromPrimitive` in this scope + --> $DIR/deriving-primitive.rs:1:10 + | +LL | #[derive(FromPrimitive)] + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/derives/deriving-with-repr-packed.rs b/src/test/ui/derives/deriving-with-repr-packed.rs new file mode 100644 index 000000000..3884e3977 --- /dev/null +++ b/src/test/ui/derives/deriving-with-repr-packed.rs @@ -0,0 +1,45 @@ +#![deny(unaligned_references)] + +// Check that deriving certain builtin traits on certain packed structs cause +// errors. This happens when the derived trait would need to use a potentially +// misaligned reference. But there are two cases that are allowed: +// - If all the fields within the struct meet the required alignment: 1 for +// `repr(packed)`, or `N` for `repr(packed(N))`. +// - If `Default` is the only trait derived, because it doesn't involve any +// references. + +#[derive(Copy, Clone, Default, PartialEq, Eq)] +//~^ ERROR `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters +//~| hard error +//~^^^ ERROR `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters +//~| hard error +#[repr(packed)] +pub struct Foo<T>(T, T, T); + +#[derive(Default, Hash)] +//~^ ERROR `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` +//~| hard error +#[repr(packed)] +pub struct Bar(u32, u32, u32); + +// This one is fine because the field alignment is 1. +#[derive(Default, Hash)] +#[repr(packed)] +pub struct Bar2(u8, i8, bool); + +// This one is fine because the field alignment is 2, matching `packed(2)`. +#[derive(Default, Hash)] +#[repr(packed(2))] +pub struct Bar3(u16, i16, bool); + +// This one is fine because it's not packed. +#[derive(Debug, Default)] +struct Y(usize); + +#[derive(Debug, Default)] +//~^ ERROR `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` +//~| hard error +#[repr(packed)] +struct X(Y); + +fn main() {} diff --git a/src/test/ui/derives/deriving-with-repr-packed.stderr b/src/test/ui/derives/deriving-with-repr-packed.stderr new file mode 100644 index 000000000..d3fe550c3 --- /dev/null +++ b/src/test/ui/derives/deriving-with-repr-packed.stderr @@ -0,0 +1,111 @@ +error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters + --> $DIR/deriving-with-repr-packed.rs:11:16 + | +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/deriving-with-repr-packed.rs:1:9 + | +LL | #![deny(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters + --> $DIR/deriving-with-repr-packed.rs:11:32 + | +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] + | ^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` + --> $DIR/deriving-with-repr-packed.rs:19:19 + | +LL | #[derive(Default, Hash)] + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` + --> $DIR/deriving-with-repr-packed.rs:39:10 + | +LL | #[derive(Debug, Default)] + | ^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 4 previous errors + +Future incompatibility report: Future breakage diagnostic: +error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters + --> $DIR/deriving-with-repr-packed.rs:11:16 + | +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/deriving-with-repr-packed.rs:1:9 + | +LL | #![deny(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + +Future breakage diagnostic: +error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters + --> $DIR/deriving-with-repr-packed.rs:11:32 + | +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] + | ^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/deriving-with-repr-packed.rs:1:9 + | +LL | #![deny(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) + +Future breakage diagnostic: +error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` + --> $DIR/deriving-with-repr-packed.rs:19:19 + | +LL | #[derive(Default, Hash)] + | ^^^^ + | +note: the lint level is defined here + --> $DIR/deriving-with-repr-packed.rs:1:9 + | +LL | #![deny(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) + +Future breakage diagnostic: +error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` + --> $DIR/deriving-with-repr-packed.rs:39:10 + | +LL | #[derive(Debug, Default)] + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/deriving-with-repr-packed.rs:1:9 + | +LL | #![deny(unaligned_references)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + diff --git a/src/test/ui/derives/issue-36617.rs b/src/test/ui/derives/issue-36617.rs new file mode 100644 index 000000000..08f293d2e --- /dev/null +++ b/src/test/ui/derives/issue-36617.rs @@ -0,0 +1,16 @@ +#![derive(Copy)] //~ ERROR cannot determine resolution for the attribute macro `derive` +//~^ ERROR `derive` attribute cannot be used at crate level + +#![test]//~ ERROR cannot determine resolution for the attribute macro `test` +//~^ ERROR `test` attribute cannot be used at crate level + +#![test_case]//~ ERROR cannot determine resolution for the attribute macro `test_case` +//~^ ERROR `test_case` attribute cannot be used at crate level + +#![bench]//~ ERROR cannot determine resolution for the attribute macro `bench` +//~^ ERROR `bench` attribute cannot be used at crate level + +#![global_allocator]//~ ERROR cannot determine resolution for the attribute macro `global_allocator` +//~^ ERROR `global_allocator` attribute cannot be used at crate level + +fn main() {} diff --git a/src/test/ui/derives/issue-36617.stderr b/src/test/ui/derives/issue-36617.stderr new file mode 100644 index 000000000..9cc0a29b0 --- /dev/null +++ b/src/test/ui/derives/issue-36617.stderr @@ -0,0 +1,97 @@ +error: cannot determine resolution for the attribute macro `derive` + --> $DIR/issue-36617.rs:1:4 + | +LL | #![derive(Copy)] + | ^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: cannot determine resolution for the attribute macro `test` + --> $DIR/issue-36617.rs:4:4 + | +LL | #![test] + | ^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: cannot determine resolution for the attribute macro `test_case` + --> $DIR/issue-36617.rs:7:4 + | +LL | #![test_case] + | ^^^^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: cannot determine resolution for the attribute macro `bench` + --> $DIR/issue-36617.rs:10:4 + | +LL | #![bench] + | ^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: cannot determine resolution for the attribute macro `global_allocator` + --> $DIR/issue-36617.rs:13:4 + | +LL | #![global_allocator] + | ^^^^^^^^^^^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: `derive` attribute cannot be used at crate level + --> $DIR/issue-36617.rs:1:1 + | +LL | #![derive(Copy)] + | ^^^^^^^^^^^^^^^^ + | +help: perhaps you meant to use an outer attribute + | +LL | #[derive(Copy)] + | ~~~~~~~~~~~~~~~ + +error: `test` attribute cannot be used at crate level + --> $DIR/issue-36617.rs:4:1 + | +LL | #![test] + | ^^^^^^^^ + | +help: perhaps you meant to use an outer attribute + | +LL | #[test] + | ~~~~~~~ + +error: `test_case` attribute cannot be used at crate level + --> $DIR/issue-36617.rs:7:1 + | +LL | #![test_case] + | ^^^^^^^^^^^^^ + | +help: perhaps you meant to use an outer attribute + | +LL | #[test_case] + | ~~~~~~~~~~~~ + +error: `bench` attribute cannot be used at crate level + --> $DIR/issue-36617.rs:10:1 + | +LL | #![bench] + | ^^^^^^^^^ + | +help: perhaps you meant to use an outer attribute + | +LL | #[bench] + | ~~~~~~~~ + +error: `global_allocator` attribute cannot be used at crate level + --> $DIR/issue-36617.rs:13:1 + | +LL | #![global_allocator] + | ^^^^^^^^^^^^^^^^^^^^ + | +help: perhaps you meant to use an outer attribute + | +LL | #[global_allocator] + | ~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 10 previous errors + diff --git a/src/test/ui/derives/issue-43023.rs b/src/test/ui/derives/issue-43023.rs new file mode 100644 index 000000000..c0208e680 --- /dev/null +++ b/src/test/ui/derives/issue-43023.rs @@ -0,0 +1,20 @@ +struct S; + +impl S { + #[derive(Debug)] //~ ERROR `derive` may only be applied to `struct`s, `enum`s and `union`s + fn f() { + file!(); + } +} + +trait Tr1 { + #[derive(Debug)] //~ ERROR `derive` may only be applied to `struct`s, `enum`s and `union`s + fn f(); +} + +trait Tr2 { + #[derive(Debug)] //~ ERROR `derive` may only be applied to `struct`s, `enum`s and `union`s + type F; +} + +fn main() {} diff --git a/src/test/ui/derives/issue-43023.stderr b/src/test/ui/derives/issue-43023.stderr new file mode 100644 index 000000000..007eb2595 --- /dev/null +++ b/src/test/ui/derives/issue-43023.stderr @@ -0,0 +1,29 @@ +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/issue-43023.rs:4:5 + | +LL | #[derive(Debug)] + | ^^^^^^^^^^^^^^^^ not applicable here +LL | / fn f() { +LL | | file!(); +LL | | } + | |_____- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/issue-43023.rs:11:5 + | +LL | #[derive(Debug)] + | ^^^^^^^^^^^^^^^^ not applicable here +LL | fn f(); + | ------- not a `struct`, `enum` or `union` + +error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s + --> $DIR/issue-43023.rs:16:5 + | +LL | #[derive(Debug)] + | ^^^^^^^^^^^^^^^^ not applicable here +LL | type F; + | ------- not a `struct`, `enum` or `union` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0774`. diff --git a/src/test/ui/derives/issue-91492.rs b/src/test/ui/derives/issue-91492.rs new file mode 100644 index 000000000..df792f118 --- /dev/null +++ b/src/test/ui/derives/issue-91492.rs @@ -0,0 +1,25 @@ +// Reproduce the issue with vec +pub struct NoDerives; +fn fun1(foo: &mut Vec<NoDerives>, bar: &[NoDerives]) { + foo.extend_from_slice(bar); //~ ERROR +} + +// Reproduce the issue with vec +// and demonstrate that other derives are ignored in the suggested output +#[derive(Default, PartialEq)] +pub struct SomeDerives; +fn fun2(foo: &mut Vec<SomeDerives>, bar: &[SomeDerives]) { + foo.extend_from_slice(bar); //~ ERROR +} + +// Try and fail to reproduce the issue without vec. +// No idea why it doesnt reproduce the issue but its still a useful test case. +struct Object<T, A>(T, A); +impl<T: Clone, A: Default> Object<T, A> { + fn use_clone(&self) {} +} +fn fun3(foo: Object<NoDerives, SomeDerives>) { + foo.use_clone(); //~ ERROR +} + +fn main() {} diff --git a/src/test/ui/derives/issue-91492.stderr b/src/test/ui/derives/issue-91492.stderr new file mode 100644 index 000000000..fbd48336d --- /dev/null +++ b/src/test/ui/derives/issue-91492.stderr @@ -0,0 +1,54 @@ +error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<NoDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91492.rs:4:9 + | +LL | pub struct NoDerives; + | -------------------- doesn't satisfy `NoDerives: Clone` +LL | fn fun1(foo: &mut Vec<NoDerives>, bar: &[NoDerives]) { +LL | foo.extend_from_slice(bar); + | ^^^^^^^^^^^^^^^^^ + | + = note: the following trait bounds were not satisfied: + `NoDerives: Clone` +help: consider annotating `NoDerives` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<SomeDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91492.rs:12:9 + | +LL | pub struct SomeDerives; + | ---------------------- doesn't satisfy `SomeDerives: Clone` +LL | fn fun2(foo: &mut Vec<SomeDerives>, bar: &[SomeDerives]) { +LL | foo.extend_from_slice(bar); + | ^^^^^^^^^^^^^^^^^ + | + = note: the following trait bounds were not satisfied: + `SomeDerives: Clone` +help: consider annotating `SomeDerives` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error[E0599]: the method `use_clone` exists for struct `Object<NoDerives, SomeDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91492.rs:22:9 + | +LL | pub struct NoDerives; + | -------------------- doesn't satisfy `NoDerives: Clone` +... +LL | struct Object<T, A>(T, A); + | ------------------- method `use_clone` not found for this struct +... +LL | foo.use_clone(); + | ^^^^^^^^^ method cannot be called on `Object<NoDerives, SomeDerives>` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NoDerives: Clone` +help: consider annotating `NoDerives` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/derives/issue-91550.rs b/src/test/ui/derives/issue-91550.rs new file mode 100644 index 000000000..56fd5ffa8 --- /dev/null +++ b/src/test/ui/derives/issue-91550.rs @@ -0,0 +1,29 @@ +use std::collections::HashSet; + +/// natural case from the issue +struct Value(u32); + +fn main() { + let hs = HashSet::<Value>::new(); + hs.insert(Value(0)); //~ ERROR +} + +/// synthetic cases +pub struct NoDerives; + +struct Object<T>(T); +impl<T: Eq> Object<T> { + fn use_eq(&self) {} +} +impl<T: Ord> Object<T> { + fn use_ord(&self) {} +} +impl<T: Ord + PartialOrd> Object<T> { + fn use_ord_and_partial_ord(&self) {} +} + +fn function(foo: Object<NoDerives>) { + foo.use_eq(); //~ ERROR + foo.use_ord(); //~ ERROR + foo.use_ord_and_partial_ord(); //~ ERROR +} diff --git a/src/test/ui/derives/issue-91550.stderr b/src/test/ui/derives/issue-91550.stderr new file mode 100644 index 000000000..12be26956 --- /dev/null +++ b/src/test/ui/derives/issue-91550.stderr @@ -0,0 +1,84 @@ +error[E0599]: the method `insert` exists for struct `HashSet<Value>`, but its trait bounds were not satisfied + --> $DIR/issue-91550.rs:8:8 + | +LL | struct Value(u32); + | ------------ + | | + | doesn't satisfy `Value: Eq` + | doesn't satisfy `Value: Hash` +... +LL | hs.insert(Value(0)); + | ^^^^^^ + | + = note: the following trait bounds were not satisfied: + `Value: Eq` + `Value: Hash` +help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]` + | +LL | #[derive(Eq, Hash, PartialEq)] + | + +error[E0599]: the method `use_eq` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91550.rs:26:9 + | +LL | pub struct NoDerives; + | -------------------- doesn't satisfy `NoDerives: Eq` +LL | +LL | struct Object<T>(T); + | ---------------- method `use_eq` not found for this struct +... +LL | foo.use_eq(); + | ^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NoDerives: Eq` +help: consider annotating `NoDerives` with `#[derive(Eq, PartialEq)]` + | +LL | #[derive(Eq, PartialEq)] + | + +error[E0599]: the method `use_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91550.rs:27:9 + | +LL | pub struct NoDerives; + | -------------------- doesn't satisfy `NoDerives: Ord` +LL | +LL | struct Object<T>(T); + | ---------------- method `use_ord` not found for this struct +... +LL | foo.use_ord(); + | ^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NoDerives: Ord` +help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]` + | +LL | #[derive(Eq, Ord, PartialEq, PartialOrd)] + | + +error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied + --> $DIR/issue-91550.rs:28:9 + | +LL | pub struct NoDerives; + | -------------------- + | | + | doesn't satisfy `NoDerives: Ord` + | doesn't satisfy `NoDerives: PartialOrd` +LL | +LL | struct Object<T>(T); + | ---------------- method `use_ord_and_partial_ord` not found for this struct +... +LL | foo.use_ord_and_partial_ord(); + | ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `NoDerives: Ord` + `NoDerives: PartialOrd` +help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]` + | +LL | #[derive(Eq, Ord, PartialEq, PartialOrd)] + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/derives/issue-97343.rs b/src/test/ui/derives/issue-97343.rs new file mode 100644 index 000000000..6f0e4d55a --- /dev/null +++ b/src/test/ui/derives/issue-97343.rs @@ -0,0 +1,8 @@ +use std::fmt::Debug; + +#[derive(Debug)] +pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter + irrelevant: Irrelevant, +} + +fn main() {} diff --git a/src/test/ui/derives/issue-97343.stderr b/src/test/ui/derives/issue-97343.stderr new file mode 100644 index 000000000..e83bbb5b6 --- /dev/null +++ b/src/test/ui/derives/issue-97343.stderr @@ -0,0 +1,21 @@ +error[E0109]: type arguments are not allowed on type parameter `Irrelevant` + --> $DIR/issue-97343.rs:4:23 + | +LL | #[derive(Debug)] + | ----- + | | + | not allowed on type parameter `Irrelevant` + | in this derive macro expansion +LL | pub struct Irrelevant<Irrelevant> { + | ^^^^^^^^^^ type argument not allowed + | +note: type parameter `Irrelevant` defined here + --> $DIR/issue-97343.rs:4:23 + | +LL | pub struct Irrelevant<Irrelevant> { + | ^^^^^^^^^^ + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0109`. |