mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
rust: pin-init: internal: pin_data: move projection struct into const _: () block
Most users would not need to mention the generated projection struct. With the upcoming self-referential support, there needs to be additional projection structs. Instead of give them publicly visible names, simply make the name not publicly accessible. A heavy user of pin projection outside kernel is for async programming. I've checked tokio codebase there is a single use case and that's for enums. Acked-by: Benno Lossin <lossin@kernel.org> Link: https://patch.msgid.link/20261006-dev-selfref-dep-v1-5-da716f740d6d@garyguo.net Signed-off-by: Gary Guo <gary@garyguo.net>
This commit is contained in:
parent
003a8953d2
commit
6fbdebfeb0
|
|
@ -186,10 +186,10 @@ pub(crate) fn pin_data(
|
|||
|
||||
Ok(quote! {
|
||||
#struct_
|
||||
#projections
|
||||
// We put the rest into this const item, because it then will not be accessible to anything
|
||||
// outside.
|
||||
const _: () = {
|
||||
#projections
|
||||
#the_pin_data
|
||||
#unpin_impl
|
||||
#drop_impl
|
||||
|
|
@ -322,7 +322,6 @@ fn generate_projections(
|
|||
let (impl_generics, ty_generics, whr) = generics.split_for_impl();
|
||||
let (_, ty_generics_with_pin_lt, _) = generics_with_pin_lt.split_for_impl();
|
||||
|
||||
let projection = format_ident!("{ident}Projection");
|
||||
let this = format_ident!("this");
|
||||
|
||||
let (fields_decl, fields_proj): (Vec<_>, Vec<_>) = fields
|
||||
|
|
@ -371,13 +370,13 @@ fn generate_projections(
|
|||
let (projection_def, projection_init) = if is_tuple_struct {
|
||||
(
|
||||
quote! {
|
||||
#vis struct #projection #generics_with_pin_lt (
|
||||
#vis struct __Projection #generics_with_pin_lt (
|
||||
#(#fields_decl)*
|
||||
::core::marker::PhantomData<&'__pin mut ()>,
|
||||
) #whr;
|
||||
},
|
||||
quote! {
|
||||
#projection(
|
||||
__Projection(
|
||||
#(#fields_proj)*
|
||||
::core::marker::PhantomData,
|
||||
)
|
||||
|
|
@ -386,7 +385,7 @@ fn generate_projections(
|
|||
} else {
|
||||
(
|
||||
quote! {
|
||||
#vis struct #projection #generics_with_pin_lt
|
||||
#vis struct __Projection #generics_with_pin_lt
|
||||
#whr
|
||||
{
|
||||
#(#fields_decl)*
|
||||
|
|
@ -394,7 +393,7 @@ fn generate_projections(
|
|||
}
|
||||
},
|
||||
quote! {
|
||||
#projection {
|
||||
__Projection {
|
||||
#(#fields_proj)*
|
||||
___pin_phantom_data: ::core::marker::PhantomData,
|
||||
}
|
||||
|
|
@ -422,7 +421,7 @@ impl #impl_generics #ident #ty_generics
|
|||
#[inline]
|
||||
#vis fn project<'__pin>(
|
||||
self: ::core::pin::Pin<&'__pin mut Self>,
|
||||
) -> #projection #ty_generics_with_pin_lt {
|
||||
) -> __Projection #ty_generics_with_pin_lt {
|
||||
// SAFETY: we only give access to `&mut` for fields not structurally pinned.
|
||||
let #this = unsafe { ::core::pin::Pin::get_unchecked_mut(self) };
|
||||
#projection_init
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user