]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/derives/deriving-with-repr-packed.rs
1 #![deny(unaligned_references)]
3 // Check that deriving certain builtin traits on certain packed structs cause
4 // errors. This happens when the derived trait would need to use a potentially
5 // misaligned reference. But there are two cases that are allowed:
6 // - If all the fields within the struct meet the required alignment: 1 for
7 // `repr(packed)`, or `N` for `repr(packed(N))`.
8 // - If `Default` is the only trait derived, because it doesn't involve any
11 #[derive(Copy, Clone, Default, PartialEq, Eq)]
12 //~^ ERROR `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters
14 //~^^^ ERROR `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
17 pub struct Foo
<T
>(T
, T
, T
);
19 #[derive(Default, Hash)]
20 //~^ ERROR `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
23 pub struct Bar(u32, u32, u32);
25 // This one is fine because the field alignment is 1.
26 #[derive(Default, Hash)]
28 pub struct Bar2(u8, i8, bool
);
30 // This one is fine because the field alignment is 2, matching `packed(2)`.
31 #[derive(Default, Hash)]
33 pub struct Bar3(u16, i16, bool
);
35 // This one is fine because it's not packed.
36 #[derive(Debug, Default)]
39 #[derive(Debug, Default)]
40 //~^ ERROR `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`