Skip to content

Commit

Permalink
tests: add many_generics
Browse files Browse the repository at this point in the history
  • Loading branch information
y86-dev committed Apr 12, 2024
1 parent 40d849d commit 8651ba6
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/many_generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use core::{marker::PhantomPinned, pin::Pin};
use pinned_init::*;

trait Bar<'a, const ID: usize = 0> {
fn bar(&mut self);
}

#[pin_data(PinnedDrop)]
struct Foo<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
where
T: Bar<'a, 1>,
{
array: [u8; 1024 * 1024],
r: &'b mut [&'a mut T; SIZE],
#[pin]
_pin: PhantomPinned,
}

#[pinned_drop]
impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> PinnedDrop for Foo<'a, 'b, T, SIZE>
where
T: Bar<'b, 1>,
{
fn drop(self: Pin<&mut Self>) {
let me = unsafe { Pin::get_unchecked_mut(self) };
for t in &mut *me.r {
Bar::<'a, 1>::bar(*t);
}
}
}

fn main() {}
147 changes: 147 additions & 0 deletions tests/ui/expand/many_generics.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
use core::{marker::PhantomPinned, pin::Pin};
use pinned_init::*;
trait Bar<'a, const ID: usize = 0> {
fn bar(&mut self);
}
struct Foo<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
where
T: Bar<'a, 1>,
{
array: [u8; 1024 * 1024],
r: &'b mut [&'a mut T; SIZE],
_pin: PhantomPinned,
}
const _: () = {
struct __ThePinData<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize>
where
T: Bar<'a, 1>,
{
__phantom: ::core::marker::PhantomData<
fn(Foo<'a, 'b, T, SIZE>) -> Foo<'a, 'b, T, SIZE>,
>,
}
impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::clone::Clone
for __ThePinData<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{
fn clone(&self) -> Self {
*self
}
}
impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::marker::Copy
for __ThePinData<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{}
#[allow(dead_code)]
impl<
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize,
> __ThePinData<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{
unsafe fn _pin<E>(
self,
slot: *mut PhantomPinned,
init: impl ::pinned_init::PinInit<PhantomPinned, E>,
) -> ::core::result::Result<(), E> {
unsafe { ::pinned_init::PinInit::__pinned_init(init, slot) }
}
unsafe fn array<E>(
self,
slot: *mut [u8; 1024 * 1024],
init: impl ::pinned_init::Init<[u8; 1024 * 1024], E>,
) -> ::core::result::Result<(), E> {
unsafe { ::pinned_init::Init::__init(init, slot) }
}
unsafe fn r<E>(
self,
slot: *mut &'b mut [&'a mut T; SIZE],
init: impl ::pinned_init::Init<&'b mut [&'a mut T; SIZE], E>,
) -> ::core::result::Result<(), E> {
unsafe { ::pinned_init::Init::__init(init, slot) }
}
}
unsafe impl<
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize,
> ::pinned_init::__internal::HasPinData for Foo<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{
type PinData = __ThePinData<'a, 'b, T, SIZE>;
unsafe fn __pin_data() -> Self::PinData {
__ThePinData {
__phantom: ::core::marker::PhantomData,
}
}
}
unsafe impl<
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize,
> ::pinned_init::__internal::PinData for __ThePinData<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{
type Datee = Foo<'a, 'b, T, SIZE>;
}
#[allow(dead_code)]
struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize>
where
T: Bar<'a, 1>,
{
__phantom_pin: ::core::marker::PhantomData<fn(&'__pin ()) -> &'__pin ()>,
__phantom: ::core::marker::PhantomData<
fn(Foo<'a, 'b, T, SIZE>) -> Foo<'a, 'b, T, SIZE>,
>,
_pin: PhantomPinned,
}
#[doc(hidden)]
impl<
'__pin,
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize,
> ::core::marker::Unpin for Foo<'a, 'b, T, SIZE>
where
__Unpin<'__pin, 'a, 'b, T, SIZE>: ::core::marker::Unpin,
T: Bar<'a, 1>,
{}
impl<'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize> ::core::ops::Drop
for Foo<'a, 'b, T, SIZE>
where
T: Bar<'a, 1>,
{
fn drop(&mut self) {
let pinned = unsafe { ::core::pin::Pin::new_unchecked(self) };
let token = unsafe { ::pinned_init::__internal::OnlyCallFromDrop::new() };
::pinned_init::PinnedDrop::drop(pinned, token);
}
}
};
unsafe impl<
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize,
> ::pinned_init::PinnedDrop for Foo<'a, 'b, T, SIZE>
where
T: Bar<'b, 1>,
{
fn drop(self: Pin<&mut Self>, _: ::pinned_init::__internal::OnlyCallFromDrop) {
let me = unsafe { Pin::get_unchecked_mut(self) };
for t in &mut *me.r {
Bar::<'a, 1>::bar(*t);
}
}
}
fn main() {}
1 change: 1 addition & 0 deletions tests/ui/expand/many_generics.rs

0 comments on commit 8651ba6

Please sign in to comment.