aboutsummaryrefslogtreecommitdiff
path: root/tests/ui/pin_project/safe_packed_borrows.rs
blob: db4ac2d02bceaef38b2a0939026deef99d8d3719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#![forbid(safe_packed_borrows)]

// Refs: https://github.com/rust-lang/rust/issues/46043

#[repr(packed)]
struct A {
    f: u32,
}

#[repr(packed(2))]
struct B {
    f: u32,
}

fn main() {
    let a = A { f: 1 };
    &a.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block

    let b = B { f: 1 };
    &b.f; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
}