mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
23ab1bda92
Migrate to a simplified safety analysis that does not use visibility. Closes https://github.com/rust-lang/project-safe-transmute/issues/15
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
//! The implementation must behave well if const values of wrong types are
|
|
//! provided.
|
|
|
|
#![crate_type = "lib"]
|
|
#![feature(adt_const_params)]
|
|
#![feature(generic_const_exprs)]
|
|
#![feature(transmutability)]
|
|
#![allow(dead_code, incomplete_features, non_camel_case_types)]
|
|
|
|
mod assert {
|
|
use std::mem::{Assume, BikeshedIntrinsicFrom};
|
|
|
|
pub fn is_transmutable<
|
|
Src,
|
|
Dst,
|
|
const ASSUME_ALIGNMENT: bool,
|
|
const ASSUME_LIFETIMES: bool,
|
|
const ASSUME_SAFETY: bool,
|
|
const ASSUME_VALIDITY: bool,
|
|
>()
|
|
where
|
|
Dst: BikeshedIntrinsicFrom<
|
|
Src,
|
|
{ from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
|
|
>,
|
|
{}
|
|
|
|
const fn from_options(
|
|
alignment: bool,
|
|
lifetimes: bool,
|
|
safety: bool,
|
|
validity: bool,
|
|
) -> Assume {
|
|
Assume {
|
|
alignment,
|
|
lifetimes,
|
|
safety,
|
|
validity,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn test() {
|
|
#[repr(C)] struct Src;
|
|
#[repr(C)] struct Dst;
|
|
assert::is_transmutable::<Src, Dst, {0u8}, false, false, false>(); //~ ERROR mismatched types
|
|
assert::is_transmutable::<Src, Dst, false, {0u8}, false, false>(); //~ ERROR mismatched types
|
|
assert::is_transmutable::<Src, Dst, false, false, {0u8}, false>(); //~ ERROR mismatched types
|
|
assert::is_transmutable::<Src, Dst, false, false, false, {0u8}>(); //~ ERROR mismatched types
|
|
}
|