2022-07-20 15:03:06 -05:00
|
|
|
// check-pass
|
|
|
|
//! The implementation should behave correctly when the `ASSUME` parameters are
|
|
|
|
//! provided indirectly through an abstraction.
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2022-08-18 14:39:14 -05:00
|
|
|
#![feature(adt_const_params)]
|
2022-07-20 15:03:06 -05:00
|
|
|
#![feature(transmutability)]
|
|
|
|
#![allow(dead_code, incomplete_features, non_camel_case_types)]
|
|
|
|
|
|
|
|
mod assert {
|
|
|
|
use std::mem::BikeshedIntrinsicFrom;
|
|
|
|
|
|
|
|
pub fn is_transmutable<
|
|
|
|
Src,
|
|
|
|
Dst,
|
|
|
|
Context,
|
2022-08-18 14:39:14 -05:00
|
|
|
const ASSUME: std::mem::Assume,
|
2022-07-20 15:03:06 -05:00
|
|
|
>()
|
|
|
|
where
|
|
|
|
Dst: BikeshedIntrinsicFrom<
|
|
|
|
Src,
|
|
|
|
Context,
|
2022-08-18 14:39:14 -05:00
|
|
|
ASSUME,
|
2022-07-20 15:03:06 -05:00
|
|
|
>,
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn direct() {
|
|
|
|
struct Context;
|
|
|
|
#[repr(C)] struct Src;
|
|
|
|
#[repr(C)] struct Dst;
|
|
|
|
|
2022-08-18 14:39:14 -05:00
|
|
|
assert::is_transmutable::<Src, Dst, Context, { std::mem::Assume::NOTHING }>();
|
2022-07-20 15:03:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn via_const() {
|
|
|
|
struct Context;
|
|
|
|
#[repr(C)] struct Src;
|
|
|
|
#[repr(C)] struct Dst;
|
|
|
|
|
|
|
|
const FALSE: bool = false;
|
|
|
|
|
2022-08-18 14:39:14 -05:00
|
|
|
assert::is_transmutable::<Src, Dst, Context, { std::mem::Assume::NOTHING }>();
|
2022-07-20 15:03:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn via_associated_const() {
|
|
|
|
struct Context;
|
|
|
|
#[repr(C)] struct Src;
|
|
|
|
#[repr(C)] struct Dst;
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
const FALSE: bool = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Ty;
|
|
|
|
|
|
|
|
impl Trait for Ty {}
|
|
|
|
|
|
|
|
assert::is_transmutable::<
|
|
|
|
Src,
|
|
|
|
Dst,
|
|
|
|
Context,
|
2022-08-18 14:39:14 -05:00
|
|
|
{
|
|
|
|
std::mem::Assume {
|
|
|
|
alignment: {Ty::FALSE},
|
|
|
|
lifetimes: {Ty::FALSE},
|
|
|
|
safety: {Ty::FALSE},
|
|
|
|
validity: {Ty::FALSE},
|
|
|
|
}
|
|
|
|
}
|
2022-07-20 15:03:06 -05:00
|
|
|
>();
|
|
|
|
}
|