Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/src/pin_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ fn generate_projections(
#[doc = #docs]
#[allow(dead_code)]
#[doc(hidden)]
#vis struct #projection #generics_with_pin_lt {
#vis struct #projection #generics_with_pin_lt
#whr
{
#(#fields_decl)*
___pin_phantom_data: ::core::marker::PhantomData<&'__pin mut ()>,
}
Expand Down
11 changes: 4 additions & 7 deletions tests/ui/expand/many_generics.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ where
/// Pin-projections of [`Foo`]
#[allow(dead_code)]
#[doc(hidden)]
struct FooProjection<
'__pin,
'a,
'b: 'a,
T: Bar<'b> + ?Sized + 'a,
const SIZE: usize = 0,
> {
struct FooProjection<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
where
T: Bar<'a, 1>,
{
array: &'__pin mut [u8; 1024 * 1024],
r: &'__pin mut &'b mut [&'a mut T; SIZE],
_pin: ::core::pin::Pin<&'__pin mut PhantomPinned>,
Expand Down
64 changes: 64 additions & 0 deletions tests/where_bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))]
#![cfg_attr(USE_RUSTC_FEATURES, feature(raw_ref_op))]

use core::marker::PhantomData;
use pin_init::*;

struct Queue<T: Iterator<Item = u8> + 'static> {
_marker: PhantomData<T>,
}

impl<T: Iterator<Item = u8> + 'static> Queue<T> {
fn new() -> impl PinInit<Self> {
init!(Self {
_marker: PhantomData,
})
}
}

#[pin_data]
struct InlineBoundHandler<T: Iterator<Item = u8> + 'static> {
#[pin]
queue: Queue<T>,
}

impl<T: Iterator<Item = u8> + 'static> InlineBoundHandler<T> {
fn new() -> impl PinInit<Self> {
pin_init!(Self {
queue <- Queue::new(),
})
}
}

#[pin_data]
struct WhereBoundHandler<T>
where
T: Iterator<Item = u8> + 'static,
{
#[pin]
queue: Queue<T>,
}

impl<T> WhereBoundHandler<T>
where
T: Iterator<Item = u8> + 'static,
{
fn new() -> impl PinInit<Self> {
pin_init!(Self {
queue <- Queue::new(),
})
}
}

#[test]
fn pin_data_preserves_inline_and_where_bounds() {
type Iter = core::iter::Empty<u8>;

stack_pin_init!(let inline = InlineBoundHandler::<Iter>::new());
let inline_proj = inline.as_mut().project();
let _ = inline_proj.queue;

stack_pin_init!(let where_ = WhereBoundHandler::<Iter>::new());
let where_proj = where_.as_mut().project();
let _ = where_proj.queue;
}
Loading