]> git.lizzy.rs Git - rust.git/blob - tests/ui/derives/deriving-with-repr-packed.rs
Rollup merge of #107354 - tspiteri:source-serif-4.005, r=GuillaumeGomez
[rust.git] / tests / ui / derives / deriving-with-repr-packed.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 // This one is fine because the fields all impl `Copy`.
12 #[derive(Default, Hash)]
13 #[repr(packed)]
14 pub struct Bar(u32, u32, u32);
15
16 // This one is fine because it's not packed.
17 #[derive(Debug, Default)]
18 struct Y(usize);
19
20 // This one has an error because `Y` doesn't impl `Copy`.
21 // Note: there is room for improvement in the error message.
22 #[derive(Debug, Default)]
23 #[repr(packed)]
24 struct X(Y);
25 //~^ ERROR cannot move out of `self` which is behind a shared reference
26
27 // This is currently allowed, but will be phased out at some point. From
28 // `zerovec` within icu4x-0.9.0.
29 #[derive(Debug)]
30 #[repr(packed)]
31 struct FlexZeroSlice {
32     width: u8,
33     data: [u8],
34     //~^ WARNING byte slice in a packed struct that derives a built-in trait
35     //~^^ this was previously accepted
36 }
37
38 fn main() {}