summaryrefslogtreecommitdiff
path: root/src/tools/miri/tests/fail/unaligned_pointers/drop_in_place.rs
blob: 8a40e527f0ebb570882a9eaf76708f8100059509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//@compile-flags: -Cdebug-assertions=no

#[repr(transparent)]
struct HasDrop(u8);

impl Drop for HasDrop {
    fn drop(&mut self) {}
}

#[repr(C, align(2))]
struct PartialDrop {
    a: HasDrop,
    b: u8,
}

//@error-pattern: /alignment 2 is required/
fn main() {
    unsafe {
        // Create an unaligned pointer
        let mut x = [0_u16; 2];
        let p = core::ptr::addr_of_mut!(x).cast::<u8>();
        let p = p.add(1);
        let p = p.cast::<PartialDrop>();

        core::ptr::drop_in_place(p);
    }
}