Skip to content

Commit

Permalink
Merge #263
Browse files Browse the repository at this point in the history
263: Fix ?Sized type parameters r=taiki-e a=alecmocatta

This is a fix for #262. Feel free to disregard and implement differently if there is a better fix I'm missing.

Fixes: #262

Co-authored-by: alecmocatta <alec@mocatta.net>
  • Loading branch information
bors[bot] and alecmocatta authored Jul 27, 2020
2 parents 78dcd19 + cde5db1 commit 2399cdc
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 20 deletions.
5 changes: 4 additions & 1 deletion examples/enum-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
// for details.
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(::pin_project::__private::PhantomData<T>, ::pin_project::__private::PhantomData<U>),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Enum<T, U> where
Expand Down
5 changes: 4 additions & 1 deletion examples/project_replace-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
// for details.
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(::pin_project::__private::PhantomData<T>, ::pin_project::__private::PhantomData<U>),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
5 changes: 4 additions & 1 deletion examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ const _: () = {
//
// See also https://github.com/taiki-e/pin-project/pull/53.
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(::pin_project::__private::PhantomData<T>, ::pin_project::__private::PhantomData<U>),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
2 changes: 1 addition & 1 deletion pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ impl<'a> Context<'a> {
// this 'public' type by creating this type in the inside of `const`.
#vis struct #struct_ident #proj_generics #where_clause {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
#lifetime, (#(#type_params),*)
#lifetime, (#(::pin_project::__private::PhantomData<#type_params>),*)
>,

#(#fields,)*
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub mod __private {
#[doc(hidden)]
pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData<T>);

impl<T: ?Sized> Unpin for AlwaysUnpin<'_, T> {}
impl<T> Unpin for AlwaysUnpin<'_, T> {}

// This is an internal helper used to ensure a value is dropped.
#[doc(hidden)]
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/default-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ const _: () = {
}
}
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
__field1: T,
}
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/default-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const _: () = {
}
}
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/default-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ const _: () = {
}
}
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/naming-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ const _: () = {
}
}
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
__field1: T,
}
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/naming-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ const _: () = {
}
}
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/naming-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ const _: () = {
}
}
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/pinned_drop-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ const _: () = {
}
}
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
__field1: T,
}
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/pinned_drop-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ const _: () = {
}
}
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ const _: () = {
}
}
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/project_replace-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ const _: () = {
}
}
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
__field1: T,
}
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/project_replace-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ const _: () = {
}
}
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ const _: () = {
}
}
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/pub-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ const _: () = {
}
}
pub struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
__field1: T,
}
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/pub-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const _: () = {
}
}
pub struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
Expand Down
8 changes: 7 additions & 1 deletion tests/expand/tests/expand/pub-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ const _: () = {
}
}
pub struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
(
::pin_project::__private::PhantomData<T>,
::pin_project::__private::PhantomData<U>,
),
>,
__field0: T,
}
impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct<T, U> where
Expand Down
13 changes: 13 additions & 0 deletions tests/sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]

use pin_project::pin_project;

#[pin_project]
struct Foo<'a, I: ?Sized, Item>
where
I: Iterator,
{
iter: &'a mut I,
item: Option<Item>,
}

0 comments on commit 2399cdc

Please sign in to comment.