]> git.lizzy.rs Git - rust.git/blob - src/test/ui/packed/packed-struct-drop-aligned.rs
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
[rust.git] / src / test / ui / packed / packed-struct-drop-aligned.rs
1 // run-pass
2 use std::cell::Cell;
3 use std::mem;
4
5 struct Aligned<'a> {
6     drop_count: &'a Cell<usize>
7 }
8
9 #[inline(never)]
10 fn check_align(ptr: *const Aligned) {
11     assert_eq!(ptr as usize % mem::align_of::<Aligned>(),
12                0);
13 }
14
15 impl<'a> Drop for Aligned<'a> {
16     fn drop(&mut self) {
17         check_align(self);
18         self.drop_count.set(self.drop_count.get() + 1);
19     }
20 }
21
22 #[repr(packed)]
23 struct Packed<'a>(u8, Aligned<'a>);
24
25 fn main() {
26     let drop_count = &Cell::new(0);
27     {
28         let mut p = Packed(0, Aligned { drop_count });
29         p.1 = Aligned { drop_count };
30         assert_eq!(drop_count.get(), 1);
31     }
32     assert_eq!(drop_count.get(), 2);
33 }