]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-99838.rs
Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup
[rust.git] / src / test / ui / issues / issue-99838.rs
1 // run-pass
2
3 use std::hint;
4
5 struct U16(u16);
6
7 impl Drop for U16 {
8     fn drop(&mut self) {
9         // Prevent LLVM from optimizing away our alignment check.
10         assert!(hint::black_box(self as *mut U16 as usize) % 2 == 0);
11     }
12 }
13
14 struct HasDrop;
15
16 impl Drop for HasDrop {
17     fn drop(&mut self) {}
18 }
19
20 struct Wrapper {
21     _a: U16,
22     b: HasDrop,
23 }
24
25 #[repr(packed)]
26 struct Misalign(u8, Wrapper);
27
28 fn main() {
29     let m = Misalign(
30         0,
31         Wrapper {
32             _a: U16(10),
33             b: HasDrop,
34         },
35     );
36     // Put it somewhere definitely even (so the `a` field is definitely at an odd address).
37     let m: ([u16; 0], Misalign) = ([], m);
38     // Move out one field, so we run custom per-field drop logic below.
39     let _x = m.1.1.b;
40 }