]> git.lizzy.rs Git - rust.git/blob - tests/ui/derives/deriving-with-repr-packed-2.rs
Auto merge of #107443 - cjgillot:generator-less-query, r=compiler-errors
[rust.git] / tests / ui / derives / deriving-with-repr-packed-2.rs
1 #![deny(unaligned_references)]
2
3 // Check that deriving certain builtin traits on certain packed structs cause
4 // errors. To avoid potentially misaligned references, field copies must be
5 // used, which involves adding `T: Copy` bounds.
6
7 #[derive(Copy, Clone, Default, PartialEq, Eq)]
8 #[repr(packed)]
9 pub struct Foo<T>(T, T, T);
10
11 struct NonCopy;
12
13 fn main() {
14     // This one is fine because `u32` impls `Copy`.
15     let x: Foo<u32> = Foo(1, 2, 3);
16     _ = x.clone();
17
18     // This one is an error because `NonCopy` doesn't impl `Copy`.
19     let x: Foo<NonCopy> = Foo(NonCopy, NonCopy, NonCopy);
20     _ = x.clone();
21     //~^ ERROR the method `clone` exists for struct `Foo<NonCopy>`, but its trait bounds were not satisfied
22 }