From af000045bd4590a0f94bfbdd0b6e37d5686db5d7 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Mon, 27 Jul 2020 12:28:47 +0100 Subject: [PATCH 1/2] fix for ?Sized type parameters --- pin-project-internal/src/pin_project/derive.rs | 2 +- src/lib.rs | 2 +- tests/sized.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/sized.rs diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index b1fd1baa..56a3d474 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -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,)* diff --git a/src/lib.rs b/src/lib.rs index 6bac6b1f..a9329068 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,7 +222,7 @@ pub mod __private { #[doc(hidden)] pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData); - impl Unpin for AlwaysUnpin<'_, T> {} + impl Unpin for AlwaysUnpin<'_, T> {} // This is an internal helper used to ensure a value is dropped. #[doc(hidden)] diff --git a/tests/sized.rs b/tests/sized.rs new file mode 100644 index 00000000..9fd7e2ba --- /dev/null +++ b/tests/sized.rs @@ -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, +} From cde5db108cc5568dcba79b187e0b21d7f5834ce3 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Mon, 27 Jul 2020 12:48:07 +0100 Subject: [PATCH 2/2] fix expandtest --- examples/enum-default-expanded.rs | 5 ++++- examples/project_replace-expanded.rs | 5 ++++- examples/struct-default-expanded.rs | 5 ++++- tests/expand/tests/expand/default-enum.expanded.rs | 8 +++++++- tests/expand/tests/expand/default-struct.expanded.rs | 8 +++++++- .../expand/tests/expand/default-tuple_struct.expanded.rs | 8 +++++++- tests/expand/tests/expand/naming-enum.expanded.rs | 8 +++++++- tests/expand/tests/expand/naming-struct.expanded.rs | 8 +++++++- tests/expand/tests/expand/naming-tuple_struct.expanded.rs | 8 +++++++- tests/expand/tests/expand/pinned_drop-enum.expanded.rs | 8 +++++++- tests/expand/tests/expand/pinned_drop-struct.expanded.rs | 8 +++++++- .../tests/expand/pinned_drop-tuple_struct.expanded.rs | 8 +++++++- .../expand/tests/expand/project_replace-enum.expanded.rs | 8 +++++++- .../tests/expand/project_replace-struct.expanded.rs | 8 +++++++- .../tests/expand/project_replace-tuple_struct.expanded.rs | 8 +++++++- tests/expand/tests/expand/pub-enum.expanded.rs | 8 +++++++- tests/expand/tests/expand/pub-struct.expanded.rs | 8 +++++++- tests/expand/tests/expand/pub-tuple_struct.expanded.rs | 8 +++++++- 18 files changed, 117 insertions(+), 18 deletions(-) diff --git a/examples/enum-default-expanded.rs b/examples/enum-default-expanded.rs index 3e7cb3c8..cea3ae59 100644 --- a/examples/enum-default-expanded.rs +++ b/examples/enum-default-expanded.rs @@ -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, ::pin_project::__private::PhantomData), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where diff --git a/examples/project_replace-expanded.rs b/examples/project_replace-expanded.rs index 661a0acd..16f47b70 100644 --- a/examples/project_replace-expanded.rs +++ b/examples/project_replace-expanded.rs @@ -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, ::pin_project::__private::PhantomData), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/examples/struct-default-expanded.rs b/examples/struct-default-expanded.rs index 53f00c9d..ff160ce8 100644 --- a/examples/struct-default-expanded.rs +++ b/examples/struct-default-expanded.rs @@ -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, ::pin_project::__private::PhantomData), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/default-enum.expanded.rs b/tests/expand/tests/expand/default-enum.expanded.rs index fd3ce99f..9e3a2037 100644 --- a/tests/expand/tests/expand/default-enum.expanded.rs +++ b/tests/expand/tests/expand/default-enum.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, __field1: T, } diff --git a/tests/expand/tests/expand/default-struct.expanded.rs b/tests/expand/tests/expand/default-struct.expanded.rs index bef7deb9..8d642a6d 100644 --- a/tests/expand/tests/expand/default-struct.expanded.rs +++ b/tests/expand/tests/expand/default-struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/default-tuple_struct.expanded.rs b/tests/expand/tests/expand/default-tuple_struct.expanded.rs index 7c1f4d22..6a6a10fd 100644 --- a/tests/expand/tests/expand/default-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/default-tuple_struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where diff --git a/tests/expand/tests/expand/naming-enum.expanded.rs b/tests/expand/tests/expand/naming-enum.expanded.rs index 8e6f5443..b97ece20 100644 --- a/tests/expand/tests/expand/naming-enum.expanded.rs +++ b/tests/expand/tests/expand/naming-enum.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, __field1: T, } diff --git a/tests/expand/tests/expand/naming-struct.expanded.rs b/tests/expand/tests/expand/naming-struct.expanded.rs index b42586e5..c72ac4b2 100644 --- a/tests/expand/tests/expand/naming-struct.expanded.rs +++ b/tests/expand/tests/expand/naming-struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/naming-tuple_struct.expanded.rs b/tests/expand/tests/expand/naming-tuple_struct.expanded.rs index b2e3a543..b1810b07 100644 --- a/tests/expand/tests/expand/naming-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/naming-tuple_struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where diff --git a/tests/expand/tests/expand/pinned_drop-enum.expanded.rs b/tests/expand/tests/expand/pinned_drop-enum.expanded.rs index 8683cf1c..ca9a75d9 100644 --- a/tests/expand/tests/expand/pinned_drop-enum.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-enum.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, __field1: T, } diff --git a/tests/expand/tests/expand/pinned_drop-struct.expanded.rs b/tests/expand/tests/expand/pinned_drop-struct.expanded.rs index e7de9cb1..904df181 100644 --- a/tests/expand/tests/expand/pinned_drop-struct.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs b/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs index 23a7cef1..0b672b18 100644 --- a/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/pinned_drop-tuple_struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where diff --git a/tests/expand/tests/expand/project_replace-enum.expanded.rs b/tests/expand/tests/expand/project_replace-enum.expanded.rs index 68ed5a71..3b9706e2 100644 --- a/tests/expand/tests/expand/project_replace-enum.expanded.rs +++ b/tests/expand/tests/expand/project_replace-enum.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, __field1: T, } diff --git a/tests/expand/tests/expand/project_replace-struct.expanded.rs b/tests/expand/tests/expand/project_replace-struct.expanded.rs index 46229c54..f1895d7a 100644 --- a/tests/expand/tests/expand/project_replace-struct.expanded.rs +++ b/tests/expand/tests/expand/project_replace-struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs b/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs index c95d804f..40fe4b33 100644 --- a/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/project_replace-tuple_struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where diff --git a/tests/expand/tests/expand/pub-enum.expanded.rs b/tests/expand/tests/expand/pub-enum.expanded.rs index 9b61d0fe..a059f939 100644 --- a/tests/expand/tests/expand/pub-enum.expanded.rs +++ b/tests/expand/tests/expand/pub-enum.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, __field1: T, } diff --git a/tests/expand/tests/expand/pub-struct.expanded.rs b/tests/expand/tests/expand/pub-struct.expanded.rs index 6696a94e..4e0363d2 100644 --- a/tests/expand/tests/expand/pub-struct.expanded.rs +++ b/tests/expand/tests/expand/pub-struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where diff --git a/tests/expand/tests/expand/pub-tuple_struct.expanded.rs b/tests/expand/tests/expand/pub-tuple_struct.expanded.rs index 99d9a101..78f86267 100644 --- a/tests/expand/tests/expand/pub-tuple_struct.expanded.rs +++ b/tests/expand/tests/expand/pub-tuple_struct.expanded.rs @@ -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, + ::pin_project::__private::PhantomData, + ), + >, __field0: T, } impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where