rust/tests/ui/transmutability/primitives/unit.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
773 B
Rust
Raw Normal View History

2023-04-09 21:22:18 +00:00
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
2023-12-14 12:11:28 +00:00
//@[next] compile-flags: -Znext-solver
2023-04-09 21:22:18 +00:00
//! The unit type, `()`, should be one byte.
#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code)]
mod assert {
use std::mem::{Assume, TransmuteFrom};
pub fn is_transmutable<Src, Dst>()
where
Dst: TransmuteFrom<Src, {
Assume::ALIGNMENT
.and(Assume::LIFETIMES)
.and(Assume::SAFETY)
.and(Assume::VALIDITY)
}>
{}
}
#[repr(C)]
struct Zst;
fn should_have_correct_size() {
assert::is_transmutable::<(), Zst>();
assert::is_transmutable::<Zst, ()>();
assert::is_transmutable::<(), u8>(); //~ ERROR cannot be safely transmuted
}