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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
//@ check-pass
#![feature(derive_coerce_pointee)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> {
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
pub trait OnDrop {
fn on_drop(&mut self);
}
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr2<'a, #[pointee] T: ?Sized, X>
where
T: OnDrop,
{
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
pub trait MyTrait<T: ?Sized> {}
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr3<'a, #[pointee] T: ?Sized, X>
where
T: MyTrait<T>,
{
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr4<'a, #[pointee] T: MyTrait<T> + ?Sized, X> {
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr5<'a, #[pointee] T: ?Sized, X>
where
Ptr5Companion<T>: MyTrait<T>,
Ptr5Companion2: MyTrait<T>,
{
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
pub struct Ptr5Companion<T: ?Sized>(core::marker::PhantomData<T>);
pub struct Ptr5Companion2;
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T> = (), const PARAM: usize = 0> {
data: &'a mut T,
x: core::marker::PhantomData<X>,
}
// a reduced example from https://lore.kernel.org/all/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com/
#[repr(transparent)]
#[derive(core::marker::CoercePointee)]
pub struct ListArc<#[pointee] T, const ID: u64 = 0>
where
T: ListArcSafe<ID> + ?Sized,
{
arc: *const T,
}
pub trait ListArcSafe<const ID: u64> {}
fn main() {}
|