Skip to content

Commit

Permalink
Tweak make_unpin_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 24, 2024
1 parent a36afd1 commit 73ca3ec
Show file tree
Hide file tree
Showing 37 changed files with 86 additions and 90 deletions.
38 changes: 17 additions & 21 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {

// Make the error message highlight `UnsafeUnpin` argument.
proj_generics.make_where_clause().predicates.push(parse_quote_spanned! { span =>
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
_pin_project::__private::Wrapper<#lifetime, Self>
>: _pin_project::UnsafeUnpin
});
Expand All @@ -714,22 +714,21 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
let lifetime = &cx.proj.lifetime;

proj_generics.make_where_clause().predicates.push(parse_quote! {
::pin_project::__private::PinnedFieldsOf<_pin_project::__private::Wrapper<
_pin_project::__private::PinnedFieldsOf<_pin_project::__private::Wrapper<
#lifetime, _pin_project::__private::PhantomPinned
>>: _pin_project::__private::Unpin
});

let (proj_impl_generics, _, proj_where_clause) = proj_generics.split_for_impl();
let (impl_generics, _, where_clause) = proj_generics.split_for_impl();
let ty_generics = cx.orig.generics.split_for_impl().1;

// For interoperability with `forbid(unsafe_code)`, `unsafe` token should be
// call-site span.
let unsafety = <Token![unsafe]>::default();
quote_spanned! { span =>
#[doc(hidden)]
impl #proj_impl_generics _pin_project::__private::Unpin
for #orig_ident #ty_generics
#proj_where_clause
impl #impl_generics _pin_project::__private::Unpin for #orig_ident #ty_generics
#where_clause
{
}

Expand All @@ -740,15 +739,14 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
// impl, they'll get a "conflicting implementations of trait" error when
// coherence checks are run.
#[doc(hidden)]
#unsafety impl #proj_impl_generics _pin_project::UnsafeUnpin
for #orig_ident #ty_generics
#proj_where_clause
#unsafety impl #impl_generics _pin_project::UnsafeUnpin for #orig_ident #ty_generics
#where_clause
{
}
}
}
UnpinImpl::Default => {
let mut full_where_clause = cx.orig.generics.where_clause.clone().unwrap();
let mut impl_where_clause = cx.orig.generics.where_clause.clone().unwrap();

// Generate a field in our new struct for every
// pinned field in the original type.
Expand Down Expand Up @@ -791,11 +789,11 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
let lifetime = &cx.proj.lifetime;
let type_params = cx.orig.generics.type_params().map(|t| &t.ident);
let proj_generics = &cx.proj.generics;
let (proj_impl_generics, proj_ty_generics, _) = proj_generics.split_for_impl();
let (_, ty_generics, where_clause) = cx.orig.generics.split_for_impl();
let (impl_generics, proj_ty_generics, _) = proj_generics.split_for_impl();
let (_, ty_generics, ty_where_clause) = cx.orig.generics.split_for_impl();

full_where_clause.predicates.push(parse_quote! {
::pin_project::__private::PinnedFieldsOf<#struct_ident #proj_ty_generics>:
impl_where_clause.predicates.push(parse_quote! {
_pin_project::__private::PinnedFieldsOf<#struct_ident #proj_ty_generics>:
_pin_project::__private::Unpin
});

Expand All @@ -811,7 +809,7 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
// However, we ensure that the user can never actually reference
// this 'public' type by creating this type in the inside of `const`.
#[allow(missing_debug_implementations)]
#vis struct #struct_ident #proj_generics #where_clause {
#vis struct #struct_ident #proj_generics #ty_where_clause {
__pin_project_use_generics: _pin_project::__private::AlwaysUnpin<
#lifetime, (#(_pin_project::__private::PhantomData<#type_params>),*)
>,
Expand All @@ -820,9 +818,8 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
#(#lifetime_fields,)*
}

impl #proj_impl_generics _pin_project::__private::Unpin
for #orig_ident #ty_generics
#full_where_clause
impl #impl_generics _pin_project::__private::Unpin for #orig_ident #ty_generics
#impl_where_clause
{
}

Expand All @@ -833,9 +830,8 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
// impl, they'll get a "conflicting implementations of trait" error when
// coherence checks are run.
#[doc(hidden)]
unsafe impl #proj_impl_generics _pin_project::UnsafeUnpin
for #orig_ident #ty_generics
#full_where_clause
unsafe impl #impl_generics _pin_project::UnsafeUnpin for #orig_ident #ty_generics
#impl_where_clause
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/default/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/default/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/default/tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/multifields/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/multifields/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/multifields/tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/enum-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/enum-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/enum-none.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/enum-own.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/enum-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Enum<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/struct-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/struct-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/struct-none.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/struct-own.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/struct-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__Struct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/expand/naming/tuple_struct-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ const _: () = {
}
impl<'pin, T, U> _pin_project::__private::Unpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
#[doc(hidden)]
unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for TupleStruct<T, U>
where
::pin_project::__private::PinnedFieldsOf<
_pin_project::__private::PinnedFieldsOf<
__TupleStruct<'pin, T, U>,
>: _pin_project::__private::Unpin,
{}
Expand Down
Loading

0 comments on commit 73ca3ec

Please sign in to comment.