about summary refs log tree commit diff
path: root/tests/ui/lint/unaligned_references_fake_borrow.rs
blob: b0ef8b471caad8726701fedf5f0247ba5420003e (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
//@ check-pass

// Regression test for <https://github.com/rust-lang/rust/issues/137250>.

// Ensure that we don't emit unaligned packed field reference errors for the fake
// borrows that we generate during match lowering. These fake borrows are there to
// ensure in *borrow-checking* that we don't modify the value being matched, but
// they are removed after the MIR is processed by `CleanupPostBorrowck`.

#[repr(packed)]
pub struct Packed(i32);

fn f(x: Packed) {
    match &x {
        Packed(4) => {},
        _ if true => {},
        _ => {}
    }

    match x {
        Packed(4) => {},
        _ if true => {},
        _ => {}
    }
}

fn main() {}