summaryrefslogtreecommitdiffstats
path: root/tests/ui/transmutability/primitives/unit.rs
blob: 12eac175106e66e18c6414865ea0e0d88762637c (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
28
29
30
31
32
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next

//! The unit type, `()`, should be one byte.

#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code)]

mod assert {
    use std::mem::{Assume, BikeshedIntrinsicFrom};

    pub fn is_transmutable<Src, Dst, Context>()
    where
        Dst: BikeshedIntrinsicFrom<Src, Context, {
            Assume::ALIGNMENT
                .and(Assume::LIFETIMES)
                .and(Assume::SAFETY)
                .and(Assume::VALIDITY)
        }>
    {}
}

#[repr(C)]
struct Zst;

fn should_have_correct_size() {
    struct Context;
    assert::is_transmutable::<(), Zst, Context>();
    assert::is_transmutable::<Zst, (), Context>();
    assert::is_transmutable::<(), u8, Context>(); //~ ERROR cannot be safely transmuted
}