2024-10-05 04:44:53 -05:00
|
|
|
#![feature(derive_coerce_pointee, arbitrary_self_types)]
|
2024-07-03 13:50:56 -05:00
|
|
|
|
2024-07-31 09:50:45 -05:00
|
|
|
extern crate core;
|
2024-10-05 04:44:53 -05:00
|
|
|
use std::marker::CoercePointee;
|
2024-07-03 13:50:56 -05:00
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`
|
2024-07-03 13:50:56 -05:00
|
|
|
enum NotStruct<'a, T: ?Sized> {
|
|
|
|
Variant(&'a T),
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: `CoercePointee` can only be derived on `struct`s with at least one field
|
2024-07-03 13:50:56 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct NoField<'a, #[pointee] T: ?Sized> {}
|
|
|
|
//~^ ERROR: lifetime parameter `'a` is never used
|
|
|
|
//~| ERROR: type parameter `T` is never used
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: `CoercePointee` can only be derived on `struct`s with at least one field
|
2024-07-03 13:50:56 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct NoFieldUnit<'a, #[pointee] T: ?Sized>();
|
|
|
|
//~^ ERROR: lifetime parameter `'a` is never used
|
|
|
|
//~| ERROR: type parameter `T` is never used
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: `CoercePointee` can only be derived on `struct`s that are generic over at least one type
|
2024-08-23 08:07:18 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct NoGeneric<'a>(&'a u8);
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits
|
2024-08-23 08:07:18 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> {
|
|
|
|
a: (&'a T1, &'a T2),
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-08-23 08:07:18 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B));
|
2024-10-05 04:44:53 -05:00
|
|
|
//~^ ERROR: only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits
|
2024-08-23 08:07:18 -05:00
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
//~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`
|
2024-07-03 13:50:56 -05:00
|
|
|
struct NotTransparent<'a, #[pointee] T: ?Sized> {
|
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-07-31 09:50:45 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct NoMaybeSized<'a, #[pointee] T> {
|
2024-10-05 04:44:53 -05:00
|
|
|
//~^ ERROR: `derive(CoercePointee)` requires T to be marked `?Sized`
|
2024-07-31 09:50:45 -05:00
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-08-20 13:53:49 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct PointeeOnField<'a, #[pointee] T: ?Sized> {
|
|
|
|
#[pointee]
|
|
|
|
//~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters
|
2024-10-05 04:44:53 -05:00
|
|
|
ptr: &'a T,
|
2024-08-20 13:53:49 -05:00
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-08-20 13:53:49 -05:00
|
|
|
#[repr(transparent)]
|
2024-10-05 04:44:53 -05:00
|
|
|
struct PointeeInTypeConstBlock<
|
|
|
|
'a,
|
|
|
|
T: ?Sized = [u32; const {
|
|
|
|
struct UhOh<#[pointee] T>(T);
|
|
|
|
//~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters
|
|
|
|
10
|
|
|
|
}],
|
|
|
|
> {
|
2024-08-20 13:53:49 -05:00
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-08-20 13:53:49 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct PointeeInConstConstBlock<
|
|
|
|
'a,
|
|
|
|
T: ?Sized,
|
2024-10-05 04:44:53 -05:00
|
|
|
const V: u32 = {
|
|
|
|
struct UhOh<#[pointee] T>(T);
|
|
|
|
//~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters
|
|
|
|
10
|
|
|
|
},
|
|
|
|
> {
|
2024-08-20 13:53:49 -05:00
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-08-20 13:53:49 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct PointeeInAnotherTypeConstBlock<'a, #[pointee] T: ?Sized> {
|
2024-10-05 04:44:53 -05:00
|
|
|
ptr: PointeeInConstConstBlock<
|
|
|
|
'a,
|
|
|
|
T,
|
|
|
|
{
|
|
|
|
struct UhOh<#[pointee] T>(T);
|
|
|
|
//~^ ERROR: the `#[pointee]` attribute may only be used on generic parameters
|
|
|
|
0
|
|
|
|
},
|
|
|
|
>,
|
2024-08-20 13:53:49 -05:00
|
|
|
}
|
|
|
|
|
2024-07-03 13:50:56 -05:00
|
|
|
// However, reordering attributes should work nevertheless.
|
|
|
|
#[repr(transparent)]
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
|
|
|
struct ThisIsAPossibleCoercePointee<'a, #[pointee] T: ?Sized> {
|
2024-07-03 13:50:56 -05:00
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-07-31 09:50:45 -05:00
|
|
|
// Also, these paths to Sized should work
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-07-31 09:50:45 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct StdSized<'a, #[pointee] T: ?std::marker::Sized> {
|
|
|
|
ptr: &'a T,
|
|
|
|
}
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-07-31 09:50:45 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct CoreSized<'a, #[pointee] T: ?core::marker::Sized> {
|
|
|
|
ptr: &'a T,
|
|
|
|
}
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-07-31 09:50:45 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct GlobalStdSized<'a, #[pointee] T: ?::std::marker::Sized> {
|
|
|
|
ptr: &'a T,
|
|
|
|
}
|
2024-10-05 04:44:53 -05:00
|
|
|
#[derive(CoercePointee)]
|
2024-07-31 09:50:45 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
struct GlobalCoreSized<'a, #[pointee] T: ?::core::marker::Sized> {
|
|
|
|
ptr: &'a T,
|
|
|
|
}
|
|
|
|
|
2024-07-03 13:50:56 -05:00
|
|
|
fn main() {}
|