diff --git a/pin-project-internal/src/lib.rs b/pin-project-internal/src/lib.rs index a6349240..0e0cc66f 100644 --- a/pin-project-internal/src/lib.rs +++ b/pin-project-internal/src/lib.rs @@ -68,6 +68,20 @@ use proc_macro::TokenStream; /// } /// ``` /// +/// By default, the visibility of the projected types and projection methods is +/// based on the original type, except `pub` which is downgraded to `pub(crate)`. +/// You can force `pub` visibility by passing a pub before the method name. +/// (In that case, you are also required to provide a name for the returned struct) +/// +/// ``` +/// # use pin_project::pin_project; +/// #[pin_project(pub project = StructProj)] //force the project method and StructProj to be pub +/// pub struct Struct { +/// #[pin] +/// field: T, +/// } +/// ``` +/// /// Note that the projection types returned by `project` and `project_ref` have /// an additional lifetime at the beginning of generics. /// @@ -76,11 +90,6 @@ use proc_macro::TokenStream; /// ^^ /// ``` /// -/// The visibility of the projected types and projection methods is based on the -/// original type. However, if the visibility of the original type is `pub`, the -/// visibility of the projected types and the projection methods is downgraded -/// to `pub(crate)`. -/// /// # Safety /// /// This attribute is completely safe. In the absence of other `unsafe` code diff --git a/pin-project-internal/src/pin_project/args.rs b/pin-project-internal/src/pin_project/args.rs index 00593dc8..d8150514 100644 --- a/pin-project-internal/src/pin_project/args.rs +++ b/pin-project-internal/src/pin_project/args.rs @@ -3,7 +3,7 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::{ - Attribute, Error, Ident, Result, Token, + Attribute, Error, Ident, Result, Token, Visibility, parse::{Parse, ParseStream}, spanned::Spanned as _, }; @@ -64,11 +64,11 @@ pub(super) struct Args { /// `UnsafeUnpin` or `!Unpin` argument. pub(super) unpin_impl: UnpinImpl, /// `project = ` argument. - pub(super) project: Option, + pub(super) project: ProjArgs, /// `project_ref = ` argument. - pub(super) project_ref: Option, + pub(super) project_ref: ProjArgs, /// `project_replace [= ]` argument. - pub(super) project_replace: ProjReplace, + pub(super) project_replace: ProjArgs, } impl Parse for Args { @@ -103,11 +103,25 @@ impl Parse for Args { let mut unsafe_unpin = None; let mut not_unpin = None; let mut project = None; + let mut project_pub = false; let mut project_ref = None; + let mut project_ref_pub = false; let mut project_replace_value = None; let mut project_replace_span = None; + let mut project_replace_pub = false; + let mut visibility_pub = None; while !input.is_empty() { + if input.peek(Token![pub]) { + let pub_token: Token![pub] = input.parse()?; + if input.is_empty() { + bail!( + pub_token, + "`pub` can only be used on project, project_ref or named project_replace" + ) + } + visibility_pub.replace(pub_token.span()); + } if input.peek(Token![!]) { let bang: Token![!] = input.parse()?; if input.is_empty() { @@ -133,9 +147,11 @@ impl Parse for Args { } "project" => { project = Some(parse_value(input, &token, project.is_some())?.0); + project_pub = visibility_pub.take().is_some(); } "project_ref" => { project_ref = Some(parse_value(input, &token, project_ref.is_some())?.0); + project_ref_pub = visibility_pub.take().is_some(); } "project_replace" => { if input.peek(Token![=]) { @@ -143,6 +159,7 @@ impl Parse for Args { parse_value(input, &token, project_replace_span.is_some())?; project_replace_value = Some(value); project_replace_span = Some(span.span()); + project_replace_pub = visibility_pub.take().is_some(); } else if project_replace_span.is_some() { bail!(token, "duplicate `project_replace` argument"); } else { @@ -158,7 +175,12 @@ impl Parse for Args { _ => bail!(token, "unexpected argument: {}", token), } } - + if let Some(span) = visibility_pub { + return Err(Error::new( + span, + "`pub` can only be used on project, project_ref or named project_replace.", + )); + } if input.is_empty() { break; } @@ -181,7 +203,6 @@ impl Parse for Args { } } } - if let Some(span) = pinned_drop { if project_replace_span.is_some() { return Err(Error::new( @@ -190,10 +211,23 @@ impl Parse for Args { )); } } - let project_replace = match (project_replace_span, project_replace_value) { - (None, _) => ProjReplace::None, - (Some(span), Some(ident)) => ProjReplace::Named { ident, span }, - (Some(span), None) => ProjReplace::Unnamed { span }, + let project_replace = + match (project_replace_span, project_replace_value, project_replace_pub) { + (None, _, _) => ProjArgs::None, + (Some(span), Some(ident), false) => ProjArgs::Named { ident, span }, + (Some(span), Some(ident), true) => ProjArgs::NamedPublic { span, ident }, + (Some(span), None, false) => ProjArgs::Unnamed { span }, + (Some(_), None, true) => unreachable!(), + }; + let project = match (project, project_pub) { + (None, _) => ProjArgs::None, + (Some(ident), false) => ProjArgs::Named { span: ident.span(), ident }, + (Some(ident), true) => ProjArgs::NamedPublic { span: ident.span(), ident }, + }; + let project_ref = match (project_ref, project_ref_pub) { + (None, _) => ProjArgs::None, + (Some(ident), false) => ProjArgs::Named { span: ident.span(), ident }, + (Some(ident), true) => ProjArgs::NamedPublic { span: ident.span(), ident }, }; let unpin_impl = match (unsafe_unpin, not_unpin) { (None, None) => UnpinImpl::Default, @@ -221,8 +255,8 @@ pub(super) enum UnpinImpl { Negative(Span), } -/// `project_replace [= ]` argument. -pub(super) enum ProjReplace { +/// `[pub] project{,_ref,_replace} [= ]` argument. +pub(super) enum ProjArgs { None, /// `project_replace`. Unnamed { @@ -233,18 +267,37 @@ pub(super) enum ProjReplace { span: Span, ident: Ident, }, + NamedPublic { + span: Span, + ident: Ident, + }, } -impl ProjReplace { +impl ProjArgs { /// Return the span of this argument. pub(super) fn span(&self) -> Option { match self { Self::None => None, - Self::Named { span, .. } | Self::Unnamed { span, .. } => Some(*span), + Self::Named { span, .. } + | Self::Unnamed { span, .. } + | Self::NamedPublic { span, .. } => Some(*span), } } pub(super) fn ident(&self) -> Option<&Ident> { - if let Self::Named { ident, .. } = self { Some(ident) } else { None } + if let Self::Named { ident, .. } | Self::NamedPublic { ident, .. } = self { + Some(ident) + } else { + None + } + } + pub(super) fn vis(&self, default_vis: &Visibility) -> Visibility { + match self { + Self::NamedPublic { .. } => parse_quote_spanned!(default_vis.span() => pub), + _ => default_vis.clone(), + } + } + pub(super) fn is_some(&self) -> bool { + !matches!(self, Self::None) } } diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index 8b620687..8b0661ba 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -10,7 +10,7 @@ use syn::{ use super::{ PIN, - args::{Args, ProjReplace, UnpinImpl, parse_args}, + args::{Args, ProjArgs, UnpinImpl, parse_args}, }; use crate::utils::{ ReplaceReceiver, SliceExt as _, Variants, determine_lifetime_name, determine_visibility, @@ -132,7 +132,8 @@ fn global_allowed_lints() -> TokenStream { /// Returns attributes used on projected types. fn proj_allowed_lints(cx: &Context<'_>) -> (TokenStream, TokenStream, TokenStream) { let global_allowed_lints = global_allowed_lints(); - let proj_mut_allowed_lints = if cx.project { Some(&global_allowed_lints) } else { None }; + let proj_mut_allowed_lints = + if cx.project.is_some() { Some(&global_allowed_lints) } else { None }; let proj_mut = quote! { #[allow( dead_code, // This lint warns unused fields/variants. @@ -141,7 +142,8 @@ fn proj_allowed_lints(cx: &Context<'_>) -> (TokenStream, TokenStream, TokenStrea clippy::mut_mut // This lint warns `&mut &mut `. )] }; - let proj_ref_allowed_lints = if cx.project_ref { Some(&global_allowed_lints) } else { None }; + let proj_ref_allowed_lints = + if cx.project_ref.is_some() { Some(&global_allowed_lints) } else { None }; let proj_ref = quote! { #[allow( dead_code, // This lint warns unused fields/variants. @@ -182,12 +184,12 @@ struct Context<'a> { pinned_drop: Option, /// `UnsafeUnpin` or `!Unpin` argument. unpin_impl: UnpinImpl, - /// `project` argument. - project: bool, - /// `project_ref` argument. - project_ref: bool, - /// `project_replace [= ]` argument. - project_replace: ProjReplace, + /// `[pub] project` argument. + project: ProjArgs, + /// `[pub] project_ref` argument. + project_ref: ProjArgs, + /// `[pub] project_replace [= ]` argument. + project_replace: ProjArgs, } impl<'a> Context<'a> { @@ -201,7 +203,7 @@ impl<'a> Context<'a> { let Args { pinned_drop, unpin_impl, project, project_ref, project_replace } = parse_args(attrs)?; - if let Some(name) = [project.as_ref(), project_ref.as_ref(), project_replace.ident()] + if let Some(name) = [project.ident(), project_ref.ident(), project_replace.ident()] .iter() .filter_map(Option::as_ref) .find(|name| **name == ident) @@ -229,18 +231,24 @@ impl<'a> Context<'a> { .ident() .cloned() .unwrap_or_else(|| format_ident!("__{}ProjectionOwned", ident)); + let mut_ident = + project.ident().cloned().unwrap_or_else(|| format_ident!("__{}Projection", ident)); + let ref_ident = project_ref + .ident() + .cloned() + .unwrap_or_else(|| format_ident!("__{}ProjectionRef", ident)); Ok(Self { kind, pinned_drop, unpin_impl, - project: project.is_some(), - project_ref: project_ref.is_some(), + project, + project_ref, project_replace, proj: ProjectedType { vis: determine_visibility(vis), - mut_ident: project.unwrap_or_else(|| format_ident!("__{}Projection", ident)), - ref_ident: project_ref.unwrap_or_else(|| format_ident!("__{}ProjectionRef", ident)), + mut_ident, + ref_ident, own_ident, lifetime, generics: proj_generics, @@ -271,7 +279,7 @@ struct OriginalType<'a> { } struct ProjectedType { - /// Visibility of the projected types. + /// Visibility of the projected type. vis: Visibility, /// Name of the projected type returned by `project` method. mut_ident: Ident, @@ -369,9 +377,10 @@ fn parse_struct<'a>( let proj_ident = &cx.proj.mut_ident; let proj_ref_ident = &cx.proj.ref_ident; let proj_own_ident = &cx.proj.own_ident; - let vis = &cx.proj.vis; + let default_vis = &cx.proj.vis; let mut orig_generics = cx.orig.generics.clone(); let orig_where_clause = orig_generics.where_clause.take(); + let orig_name = cx.orig.ident; let proj_generics = &cx.proj.generics; let proj_where_clause = &cx.proj.where_clause; @@ -392,18 +401,39 @@ fn parse_struct<'a>( }; let (proj_attrs, proj_ref_attrs, proj_own_attrs) = proj_allowed_lints(cx); - generate.extend(cx.project, quote! { + + let project_vis = cx.project.vis(default_vis); + let project_doc = format!( + "A projected {0}. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut {0}> directly rather than this struct", + orig_name + ); + generate.extend(cx.project.is_some(), quote! { #proj_attrs - #vis struct #proj_ident #proj_generics #where_clause_fields + #[doc = #project_doc] + #[non_exhaustive] + #project_vis struct #proj_ident #proj_generics #where_clause_fields }); - generate.extend(cx.project_ref, quote! { + + let project_ref_doc = format!( + "A immutably projected {0}. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& {0}> directly rather than this struct",orig_name); + let project_ref_vis = cx.project_ref.vis(default_vis); + generate.extend(cx.project_ref.is_some(), quote! { #proj_ref_attrs - #vis struct #proj_ref_ident #proj_generics #where_clause_ref_fields + #[doc = #project_ref_doc] + #[non_exhaustive] + #project_ref_vis struct #proj_ref_ident #proj_generics #where_clause_ref_fields }); + + let project_own_doc = format!("A projection that own a {0}.", orig_name); + let project_own_vis = cx.project_replace.vis(default_vis); if cx.project_replace.span().is_some() { generate.extend(cx.project_replace.ident().is_some(), quote! { #proj_own_attrs - #vis struct #proj_own_ident #orig_generics #where_clause_own_fields + #[doc = #project_own_doc] + #[non_exhaustive] + #project_own_vis struct #proj_own_ident #orig_generics #where_clause_own_fields }); } @@ -431,7 +461,7 @@ fn parse_enum<'a>( variants: &'a Punctuated, generate: &mut GenerateTokens, ) -> Result<()> { - if let ProjReplace::Unnamed { span } = &cx.project_replace { + if let ProjArgs::Unnamed { span } = &cx.project_replace { return Err(Error::new( *span, "`project_replace` argument requires a value when used on enums", @@ -459,33 +489,37 @@ fn parse_enum<'a>( let proj_ident = &cx.proj.mut_ident; let proj_ref_ident = &cx.proj.ref_ident; let proj_own_ident = &cx.proj.own_ident; - let vis = &cx.proj.vis; + let default_vis = &cx.proj.vis; let mut orig_generics = cx.orig.generics.clone(); let orig_where_clause = orig_generics.where_clause.take(); let proj_generics = &cx.proj.generics; let proj_where_clause = &cx.proj.where_clause; let (proj_attrs, proj_ref_attrs, proj_own_attrs) = proj_allowed_lints(cx); - if cx.project { + + let project_vis = cx.project.vis(default_vis); + if cx.project.is_some() { generate.extend(true, quote! { #proj_attrs - #vis enum #proj_ident #proj_generics #proj_where_clause { + #project_vis enum #proj_ident #proj_generics #proj_where_clause { #proj_variants } }); } - if cx.project_ref { + let project_ref_vis = cx.project_ref.vis(default_vis); + if cx.project_ref.is_some() { generate.extend(true, quote! { #proj_ref_attrs - #vis enum #proj_ref_ident #proj_generics #proj_where_clause { + #project_ref_vis enum #proj_ref_ident #proj_generics #proj_where_clause { #proj_ref_variants } }); } + let project_own_vis = cx.project_replace.vis(default_vis); if cx.project_replace.ident().is_some() { generate.extend(true, quote! { #proj_own_attrs - #vis enum #proj_own_ident #orig_generics #orig_where_clause { + #project_own_vis enum #proj_own_ident #orig_generics #orig_where_clause { #proj_own_variants } }); @@ -590,14 +624,18 @@ fn visit_fields<'a>( let binding = ident.clone().unwrap_or_else(|| format_ident!("_{}", i)); proj_pat.extend(quote!(#binding,)); let lifetime = &cx.proj.lifetime; + let doc = attrs.extract_doc(); if attrs.position_exact(PIN)?.is_some() { proj_fields.extend(quote! { + #doc #vis #ident #colon_token ::pin_project::__private::Pin<&#lifetime mut (#ty)>, }); proj_ref_fields.extend(quote! { + #doc #vis #ident #colon_token ::pin_project::__private::Pin<&#lifetime (#ty)>, }); proj_own_fields.extend(quote! { + #doc #vis #ident #colon_token ::pin_project::__private::PhantomData<#ty>, }); proj_body.extend(quote! { @@ -611,12 +649,15 @@ fn visit_fields<'a>( pinned_bindings.push(binding); } else { proj_fields.extend(quote! { + #doc #vis #ident #colon_token &#lifetime mut (#ty), }); proj_ref_fields.extend(quote! { + #doc #vis #ident #colon_token &#lifetime (#ty), }); proj_own_fields.extend(quote! { + #doc #vis #ident #colon_token #ty, }); proj_body.extend(quote! { @@ -945,7 +986,7 @@ fn make_proj_impl( proj_ref_body: &TokenStream, proj_own_body: &TokenStream, ) -> TokenStream { - let vis = &cx.proj.vis; + let default_vis = &cx.proj.vis; let lifetime = &cx.proj.lifetime; let orig_ident = cx.orig.ident; let proj_ident = &cx.proj.mut_ident; @@ -953,6 +994,7 @@ fn make_proj_impl( let proj_own_ident = &cx.proj.own_ident; let orig_ty_generics = cx.orig.generics.split_for_impl().1; + let orig_name = cx.orig.ident; let proj_ty_generics = cx.proj.generics.split_for_impl().1; let (impl_generics, ty_generics, where_clause) = cx.orig.generics.split_for_impl(); // TODO: For enums and project_replace, dead_code warnings should not be @@ -961,10 +1003,15 @@ fn make_proj_impl( // code, so we allow warnings for all methods for now. let allow_dead_code = quote! { #[allow(dead_code)] }; + let project_vis = cx.project.vis(default_vis); + let project_doc = format!( + "Take a Pin<&mut {0}> and project it, aka return a {0}-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self",orig_name); let mut project = Some(quote! { #allow_dead_code #[inline] - #vis fn project<#lifetime>( + #[doc = #project_doc] + #project_vis fn project<#lifetime>( self: _pin_project::__private::Pin<&#lifetime mut Self>, ) -> #proj_ident #proj_ty_generics { unsafe { @@ -972,10 +1019,17 @@ fn make_proj_impl( } } }); + + let project_ref_vis = cx.project_ref.vis(default_vis); + let project_ref_doc = format!( + "Take a Pin<& {0}> and project it, aka return a {0}-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self",orig_name + ); let mut project_ref = Some(quote! { #allow_dead_code #[inline] - #vis fn project_ref<#lifetime>( + #[doc = #project_ref_doc] + #project_ref_vis fn project_ref<#lifetime>( self: _pin_project::__private::Pin<&#lifetime Self>, ) -> #proj_ref_ident #proj_ty_generics { unsafe { @@ -983,10 +1037,16 @@ fn make_proj_impl( } } }); + + let project_own_vis = cx.project_replace.vis(default_vis); + let project_own_doc = format!( + "Take a Pin<&mut {0}>, and a replacement. Replace the pinned {0} and return an owning projection", + orig_name + ); let mut project_replace = cx.project_replace.span().map(|span| { // It is enough to only set the span of the signature. let sig = quote_spanned! { span => - #vis fn project_replace( + #project_own_vis fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, ) -> #proj_own_ident #orig_ty_generics @@ -994,6 +1054,7 @@ fn make_proj_impl( quote! { #allow_dead_code #[inline] + #[doc = #project_own_doc] #sig { unsafe { let __self_ptr: *mut Self = self.get_unchecked_mut(); @@ -1012,10 +1073,10 @@ fn make_proj_impl( }); if cx.kind == Enum { - if !cx.project { + if !cx.project.is_some() { project = None; } - if !cx.project_ref { + if !cx.project_ref.is_some() { project_ref = None; } if cx.project_replace.ident().is_none() { diff --git a/pin-project-internal/src/utils.rs b/pin-project-internal/src/utils.rs index 2e66247b..738c37ee 100644 --- a/pin-project-internal/src/utils.rs +++ b/pin-project-internal/src/utils.rs @@ -74,7 +74,7 @@ pub(crate) fn insert_lifetime(generics: &mut Generics, lifetime: Lifetime) { generics.params.insert(0, LifetimeParam::new(lifetime).into()); } -/// Determines the visibility of the projected types and projection methods. +/// Determines the default visibility of the projected types and projection methods. /// /// If given visibility is `pub`, returned visibility is `pub(crate)`. /// Otherwise, returned visibility is the same as given visibility. @@ -111,6 +111,7 @@ fn respan_tokens(tokens: TokenStream, span: Span) -> TokenStream { pub(crate) trait SliceExt { fn position_exact(&self, ident: &str) -> Result>; fn find(&self, ident: &str) -> Option<&Attribute>; + fn extract_doc(&self) -> TokenStream; } impl SliceExt for [Attribute] { @@ -135,6 +136,16 @@ impl SliceExt for [Attribute] { fn find(&self, ident: &str) -> Option<&Attribute> { self.iter().position(|attr| attr.path().is_ident(ident)).map(|i| &self[i]) } + fn extract_doc(&self) -> TokenStream { + let mut doc = TokenStream::new(); + for doc_item in self.iter().filter(|attr| attr.path().is_ident("doc")) { + doc = quote! { + #doc + #doc_item + }; + } + doc + } } pub(crate) trait ParseBufferExt<'a> { diff --git a/tests/expand/default/enum.expanded.rs b/tests/expand/default/enum.expanded.rs index 09de1f67..d808d6e1 100644 --- a/tests/expand/default/enum.expanded.rs +++ b/tests/expand/default/enum.expanded.rs @@ -88,6 +88,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -111,6 +113,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { diff --git a/tests/expand/default/struct.expanded.rs b/tests/expand/default/struct.expanded.rs index 33abccbc..29aa43bf 100644 --- a/tests/expand/default/struct.expanded.rs +++ b/tests/expand/default/struct.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,6 +55,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -62,6 +70,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/default/tuple_struct.expanded.rs b/tests/expand/default/tuple_struct.expanded.rs index 63568659..1d7766a9 100644 --- a/tests/expand/default/tuple_struct.expanded.rs +++ b/tests/expand/default/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -43,6 +49,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -56,6 +64,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/explicit_pub/enum.expanded.rs b/tests/expand/explicit_pub/enum.expanded.rs new file mode 100644 index 00000000..c173d903 --- /dev/null +++ b/tests/expand/explicit_pub/enum.expanded.rs @@ -0,0 +1,174 @@ +use pin_project::pin_project; +#[pin(__private(pub project = EnumProj, pub project_ref = EnumProjRef))] +pub enum Enum { + Struct { #[pin] pinned: T, unpinned: U }, + Tuple(#[pin] T, U), + Unit, +} +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items, + clippy::mut_mut +)] +pub enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items, + clippy::ref_option_ref +)] +pub enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { pinned: ::pin_project::__private::Pin<&'pin (T)>, unpinned: &'pin (U) }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow( + unused_qualifications, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::elidable_lifetime_names, + clippy::missing_const_for_fn, + clippy::needless_lifetimes, + clippy::semicolon_if_nothing_returned, + clippy::use_self, + clippy::used_underscore_binding +)] +const _: () = { + #[allow(unused_extern_crates)] + extern crate pin_project as _pin_project; + impl Enum { + #[allow(dead_code)] + #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ + pub fn project<'pin>( + self: _pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => { + EnumProj::Struct { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + Self::Tuple(_0, _1) => { + EnumProj::Tuple( + _pin_project::__private::Pin::new_unchecked(_0), + _1, + ) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(dead_code)] + #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ + pub fn project_ref<'pin>( + self: _pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => { + EnumProjRef::Struct { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple( + _pin_project::__private::Pin::new_unchecked(_0), + _1, + ) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(missing_debug_implementations, unnameable_types)] + pub struct __Enum<'pin, T, U> { + __pin_project_use_generics: _pin_project::__private::AlwaysUnpin< + 'pin, + ( + _pin_project::__private::PhantomData, + _pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> _pin_project::__private::Unpin for Enum + where + _pin_project::__private::PinnedFieldsOf< + __Enum<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + #[doc(hidden)] + unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Enum + where + _pin_project::__private::PinnedFieldsOf< + __Enum<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl _pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: _pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/explicit_pub/enum.rs b/tests/expand/explicit_pub/enum.rs new file mode 100644 index 00000000..7fa9c8f0 --- /dev/null +++ b/tests/expand/explicit_pub/enum.rs @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use pin_project::pin_project; + +#[pin_project(pub project = EnumProj, pub project_ref = EnumProjRef)] +pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/explicit_pub/struct.expanded.rs b/tests/expand/explicit_pub/struct.expanded.rs new file mode 100644 index 00000000..663663f2 --- /dev/null +++ b/tests/expand/explicit_pub/struct.expanded.rs @@ -0,0 +1,166 @@ +use pin_project::pin_project; +/// Test Struct +#[pin(__private(pub project = StructProj, project_ref = StructProjRef))] +pub struct Struct { + /// Pinned field + #[pin] + pub pinned: T, + /// UnPinned field + pub unpinned: U, +} +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items, + clippy::mut_mut +)] +/**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ +#[non_exhaustive] +pub struct StructProj<'pin, T, U> +where + Struct: 'pin, +{ + /// Pinned field + pub pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + /// UnPinned field + pub unpinned: &'pin mut (U), +} +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items, + clippy::ref_option_ref +)] +/**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ +#[non_exhaustive] +pub(crate) struct StructProjRef<'pin, T, U> +where + Struct: 'pin, +{ + /// Pinned field + pub pinned: ::pin_project::__private::Pin<&'pin (T)>, + /// UnPinned field + pub unpinned: &'pin (U), +} +#[allow( + unused_qualifications, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::elidable_lifetime_names, + clippy::missing_const_for_fn, + clippy::needless_lifetimes, + clippy::semicolon_if_nothing_returned, + clippy::use_self, + clippy::used_underscore_binding +)] +const _: () = { + #[allow(unused_extern_crates)] + extern crate pin_project as _pin_project; + impl Struct { + #[allow(dead_code)] + #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ + pub fn project<'pin>( + self: _pin_project::__private::Pin<&'pin mut Self>, + ) -> StructProj<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + StructProj { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(dead_code)] + #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ + pub(crate) fn project_ref<'pin>( + self: _pin_project::__private::Pin<&'pin Self>, + ) -> StructProjRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + StructProjRef { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations, unnameable_types)] + pub struct __Struct<'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 + _pin_project::__private::PinnedFieldsOf< + __Struct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + #[doc(hidden)] + unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct + where + _pin_project::__private::PinnedFieldsOf< + __Struct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl _pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: _pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/explicit_pub/struct.rs b/tests/expand/explicit_pub/struct.rs new file mode 100644 index 00000000..bd1f9d28 --- /dev/null +++ b/tests/expand/explicit_pub/struct.rs @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use pin_project::pin_project; + +/// Test Struct +#[pin_project(pub project = StructProj, project_ref = StructProjRef)] +pub struct Struct { + /// Pinned field + #[pin] + pub pinned: T, + /// UnPinned field + pub unpinned: U, +} + +fn main() {} diff --git a/tests/expand/explicit_pub/struct_replace.expanded.rs b/tests/expand/explicit_pub/struct_replace.expanded.rs new file mode 100644 index 00000000..280609e4 --- /dev/null +++ b/tests/expand/explicit_pub/struct_replace.expanded.rs @@ -0,0 +1,174 @@ +use pin_project::pin_project; +#[pin(__private(pub project_replace = StructProjReplace))] +pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, +} +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items +)] +///A projection that own a Struct. +#[non_exhaustive] +pub struct StructProjReplace { + pub pinned: ::pin_project::__private::PhantomData, + pub unpinned: U, +} +#[allow( + unused_qualifications, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::elidable_lifetime_names, + clippy::missing_const_for_fn, + clippy::needless_lifetimes, + clippy::semicolon_if_nothing_returned, + clippy::use_self, + clippy::used_underscore_binding +)] +const _: () = { + #[allow(unused_extern_crates)] + extern crate pin_project as _pin_project; + #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] + pub(crate) struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pub pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + pub unpinned: &'pin mut (U), + } + #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] + pub(crate) struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pub pinned: ::pin_project::__private::Pin<&'pin (T)>, + pub unpinned: &'pin (U), + } + impl Struct { + #[allow(dead_code)] + #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ + pub(crate) fn project<'pin>( + self: _pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(dead_code)] + #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ + pub(crate) fn project_ref<'pin>( + self: _pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: _pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(dead_code)] + #[inline] + ///Take a Pin<&mut Struct>, and a replacement. Replace the pinned Struct and return an owning projection + pub fn project_replace( + self: _pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> StructProjReplace { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = _pin_project::__private::UnsafeOverwriteGuard::new( + __self_ptr, + __replacement, + ); + let Self { pinned, unpinned } = &mut *__self_ptr; + let __result = StructProjReplace { + pinned: _pin_project::__private::PhantomData, + unpinned: _pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = _pin_project::__private::UnsafeDropInPlaceGuard::new( + pinned, + ); + } + __result + } + } + } + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations, unnameable_types)] + pub struct __Struct<'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 + _pin_project::__private::PinnedFieldsOf< + __Struct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + #[doc(hidden)] + unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for Struct + where + _pin_project::__private::PinnedFieldsOf< + __Struct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl _pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: _pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/explicit_pub/struct_replace.rs b/tests/expand/explicit_pub/struct_replace.rs new file mode 100644 index 00000000..2096db82 --- /dev/null +++ b/tests/expand/explicit_pub/struct_replace.rs @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use pin_project::pin_project; + +#[pin_project(pub project_replace = StructProjReplace)] +pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, +} + +fn main() {} diff --git a/tests/expand/explicit_pub/tuple_struct.expanded.rs b/tests/expand/explicit_pub/tuple_struct.expanded.rs new file mode 100644 index 00000000..d190bb2a --- /dev/null +++ b/tests/expand/explicit_pub/tuple_struct.expanded.rs @@ -0,0 +1,133 @@ +use pin_project::pin_project; +#[pin(__private(pub project = TupleStructProj))] +pub struct TupleStruct(#[pin] pub T, pub U); +#[allow( + dead_code, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::missing_docs_in_private_items, + clippy::mut_mut +)] +/**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ +#[non_exhaustive] +pub struct TupleStructProj<'pin, T, U>( + pub ::pin_project::__private::Pin<&'pin mut (T)>, + pub &'pin mut (U), +) +where + TupleStruct: 'pin; +#[allow( + unused_qualifications, + deprecated, + explicit_outlives_requirements, + single_use_lifetimes, + unreachable_pub, + unused_tuple_struct_fields, + clippy::unknown_clippy_lints, + clippy::absolute_paths, + clippy::min_ident_chars, + clippy::pattern_type_mismatch, + clippy::pub_with_shorthand, + clippy::redundant_pub_crate, + clippy::single_char_lifetime_names, + clippy::type_repetition_in_bounds, + clippy::elidable_lifetime_names, + clippy::missing_const_for_fn, + clippy::needless_lifetimes, + clippy::semicolon_if_nothing_returned, + clippy::use_self, + clippy::used_underscore_binding +)] +const _: () = { + #[allow(unused_extern_crates)] + extern crate pin_project as _pin_project; + #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] + pub(crate) struct __TupleStructProjectionRef<'pin, T, U>( + pub ::pin_project::__private::Pin<&'pin (T)>, + pub &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + #[allow(dead_code)] + #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ + pub fn project<'pin>( + self: _pin_project::__private::Pin<&'pin mut Self>, + ) -> TupleStructProj<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + TupleStructProj(_pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(dead_code)] + #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ + pub(crate) fn project_ref<'pin>( + self: _pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef( + _pin_project::__private::Pin::new_unchecked(_0), + _1, + ) + } + } + } + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations, unnameable_types)] + pub struct __TupleStruct<'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 + _pin_project::__private::PinnedFieldsOf< + __TupleStruct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + #[doc(hidden)] + unsafe impl<'pin, T, U> _pin_project::UnsafeUnpin for TupleStruct + where + _pin_project::__private::PinnedFieldsOf< + __TupleStruct<'pin, T, U>, + >: _pin_project::__private::Unpin, + {} + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl _pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: _pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/explicit_pub/tuple_struct.rs b/tests/expand/explicit_pub/tuple_struct.rs new file mode 100644 index 00000000..7223617d --- /dev/null +++ b/tests/expand/explicit_pub/tuple_struct.rs @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use pin_project::pin_project; + +#[pin_project(pub project = TupleStructProj)] +pub struct TupleStruct(#[pin] pub T, pub U); + +fn main() {} diff --git a/tests/expand/multifields/enum.expanded.rs b/tests/expand/multifields/enum.expanded.rs index 771d99d6..dce8cbb0 100644 --- a/tests/expand/multifields/enum.expanded.rs +++ b/tests/expand/multifields/enum.expanded.rs @@ -145,6 +145,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -176,6 +178,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { @@ -207,6 +211,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Enum>, and a replacement. Replace the pinned Enum and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/multifields/struct.expanded.rs b/tests/expand/multifields/struct.expanded.rs index ac0138c6..bca3b8a4 100644 --- a/tests/expand/multifields/struct.expanded.rs +++ b/tests/expand/multifields/struct.expanded.rs @@ -34,6 +34,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -44,6 +47,9 @@ const _: () = { unpinned2: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -54,6 +60,8 @@ const _: () = { unpinned2: &'pin (U), } #[allow(dead_code, clippy::missing_docs_in_private_items)] + ///A projection that own a Struct. + #[non_exhaustive] struct __StructProjectionOwned { pinned1: ::pin_project::__private::PhantomData, pinned2: ::pin_project::__private::PhantomData, @@ -63,6 +71,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -79,6 +89,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { @@ -94,6 +106,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Struct>, and a replacement. Replace the pinned Struct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/multifields/tuple_struct.expanded.rs b/tests/expand/multifields/tuple_struct.expanded.rs index ab351c4b..ca5d461b 100644 --- a/tests/expand/multifields/tuple_struct.expanded.rs +++ b/tests/expand/multifields/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, ::pin_project::__private::Pin<&'pin mut (T)>, @@ -36,6 +39,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, ::pin_project::__private::Pin<&'pin (T)>, @@ -45,6 +51,8 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items)] + ///A projection that own a TupleStruct. + #[non_exhaustive] struct __TupleStructProjectionOwned( ::pin_project::__private::PhantomData, ::pin_project::__private::PhantomData, @@ -54,6 +62,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -69,6 +79,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { @@ -84,6 +96,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut TupleStruct>, and a replacement. Replace the pinned TupleStruct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/enum-all.expanded.rs b/tests/expand/naming/enum-all.expanded.rs index 05cb1bab..7ef5379b 100644 --- a/tests/expand/naming/enum-all.expanded.rs +++ b/tests/expand/naming/enum-all.expanded.rs @@ -112,6 +112,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { @@ -132,6 +134,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { @@ -155,6 +159,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Enum>, and a replacement. Replace the pinned Enum and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/enum-mut.expanded.rs b/tests/expand/naming/enum-mut.expanded.rs index b2fe404a..cd64b71a 100644 --- a/tests/expand/naming/enum-mut.expanded.rs +++ b/tests/expand/naming/enum-mut.expanded.rs @@ -62,6 +62,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { diff --git a/tests/expand/naming/enum-own.expanded.rs b/tests/expand/naming/enum-own.expanded.rs index 1e85f5bb..bba564b1 100644 --- a/tests/expand/naming/enum-own.expanded.rs +++ b/tests/expand/naming/enum-own.expanded.rs @@ -57,6 +57,7 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Enum>, and a replacement. Replace the pinned Enum and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/enum-ref.expanded.rs b/tests/expand/naming/enum-ref.expanded.rs index 4d9d5586..71d7da23 100644 --- a/tests/expand/naming/enum-ref.expanded.rs +++ b/tests/expand/naming/enum-ref.expanded.rs @@ -59,6 +59,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { diff --git a/tests/expand/naming/struct-all.expanded.rs b/tests/expand/naming/struct-all.expanded.rs index 35d225ed..d928d837 100644 --- a/tests/expand/naming/struct-all.expanded.rs +++ b/tests/expand/naming/struct-all.expanded.rs @@ -23,6 +23,9 @@ struct Struct { clippy::missing_docs_in_private_items, clippy::mut_mut )] +/**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ +#[non_exhaustive] struct Proj<'pin, T, U> where Struct: 'pin, @@ -48,6 +51,9 @@ where clippy::missing_docs_in_private_items, clippy::ref_option_ref )] +/**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ +#[non_exhaustive] struct ProjRef<'pin, T, U> where Struct: 'pin, @@ -72,6 +78,8 @@ where clippy::type_repetition_in_bounds, clippy::missing_docs_in_private_items )] +///A projection that own a Struct. +#[non_exhaustive] struct ProjOwn { pinned: ::pin_project::__private::PhantomData, unpinned: U, @@ -104,6 +112,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { @@ -117,6 +127,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { @@ -130,6 +142,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Struct>, and a replacement. Replace the pinned Struct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/struct-mut.expanded.rs b/tests/expand/naming/struct-mut.expanded.rs index 7d3c4f3a..393b5576 100644 --- a/tests/expand/naming/struct-mut.expanded.rs +++ b/tests/expand/naming/struct-mut.expanded.rs @@ -23,6 +23,9 @@ struct Struct { clippy::missing_docs_in_private_items, clippy::mut_mut )] +/**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ +#[non_exhaustive] struct Proj<'pin, T, U> where Struct: 'pin, @@ -56,6 +59,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -66,6 +72,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { @@ -79,6 +87,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/naming/struct-none.expanded.rs b/tests/expand/naming/struct-none.expanded.rs index 33abccbc..29aa43bf 100644 --- a/tests/expand/naming/struct-none.expanded.rs +++ b/tests/expand/naming/struct-none.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,6 +55,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -62,6 +70,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/naming/struct-own.expanded.rs b/tests/expand/naming/struct-own.expanded.rs index 96a58e26..afdf34d8 100644 --- a/tests/expand/naming/struct-own.expanded.rs +++ b/tests/expand/naming/struct-own.expanded.rs @@ -22,6 +22,8 @@ struct Struct { clippy::type_repetition_in_bounds, clippy::missing_docs_in_private_items )] +///A projection that own a Struct. +#[non_exhaustive] struct ProjOwn { pinned: ::pin_project::__private::PhantomData, unpinned: U, @@ -52,6 +54,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -60,6 +65,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -70,6 +78,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -83,6 +93,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { @@ -96,6 +108,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Struct>, and a replacement. Replace the pinned Struct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/struct-ref.expanded.rs b/tests/expand/naming/struct-ref.expanded.rs index 5c9e1e9e..92429904 100644 --- a/tests/expand/naming/struct-ref.expanded.rs +++ b/tests/expand/naming/struct-ref.expanded.rs @@ -23,6 +23,9 @@ struct Struct { clippy::missing_docs_in_private_items, clippy::ref_option_ref )] +/**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ +#[non_exhaustive] struct ProjRef<'pin, T, U> where Struct: 'pin, @@ -56,6 +59,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -66,6 +72,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -79,6 +87,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { diff --git a/tests/expand/naming/tuple_struct-all.expanded.rs b/tests/expand/naming/tuple_struct-all.expanded.rs index 467b820e..0301eeee 100644 --- a/tests/expand/naming/tuple_struct-all.expanded.rs +++ b/tests/expand/naming/tuple_struct-all.expanded.rs @@ -19,6 +19,9 @@ struct TupleStruct(#[pin] T, U); clippy::missing_docs_in_private_items, clippy::mut_mut )] +/**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ +#[non_exhaustive] struct Proj<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -43,6 +46,9 @@ where clippy::missing_docs_in_private_items, clippy::ref_option_ref )] +/**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ +#[non_exhaustive] struct ProjRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -66,6 +72,8 @@ where clippy::type_repetition_in_bounds, clippy::missing_docs_in_private_items )] +///A projection that own a TupleStruct. +#[non_exhaustive] struct ProjOwn(::pin_project::__private::PhantomData, U); #[allow( unused_qualifications, @@ -95,6 +103,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { @@ -105,6 +115,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { @@ -115,6 +127,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut TupleStruct>, and a replacement. Replace the pinned TupleStruct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/tuple_struct-mut.expanded.rs b/tests/expand/naming/tuple_struct-mut.expanded.rs index 22e49040..f22174e5 100644 --- a/tests/expand/naming/tuple_struct-mut.expanded.rs +++ b/tests/expand/naming/tuple_struct-mut.expanded.rs @@ -19,6 +19,9 @@ struct TupleStruct(#[pin] T, U); clippy::missing_docs_in_private_items, clippy::mut_mut )] +/**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ +#[non_exhaustive] struct Proj<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -51,6 +54,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -60,6 +66,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> Proj<'pin, T, U> { @@ -70,6 +78,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/naming/tuple_struct-none.expanded.rs b/tests/expand/naming/tuple_struct-none.expanded.rs index 63568659..1d7766a9 100644 --- a/tests/expand/naming/tuple_struct-none.expanded.rs +++ b/tests/expand/naming/tuple_struct-none.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -43,6 +49,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -56,6 +64,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/naming/tuple_struct-own.expanded.rs b/tests/expand/naming/tuple_struct-own.expanded.rs index 4b0ea0ed..5da89fae 100644 --- a/tests/expand/naming/tuple_struct-own.expanded.rs +++ b/tests/expand/naming/tuple_struct-own.expanded.rs @@ -18,6 +18,8 @@ struct TupleStruct(#[pin] T, U); clippy::type_repetition_in_bounds, clippy::missing_docs_in_private_items )] +///A projection that own a TupleStruct. +#[non_exhaustive] struct ProjOwn(::pin_project::__private::PhantomData, U); #[allow( unused_qualifications, @@ -45,6 +47,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -52,6 +57,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -61,6 +69,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -74,6 +84,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { @@ -87,6 +99,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut TupleStruct>, and a replacement. Replace the pinned TupleStruct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/naming/tuple_struct-ref.expanded.rs b/tests/expand/naming/tuple_struct-ref.expanded.rs index 688ad1eb..b58e977c 100644 --- a/tests/expand/naming/tuple_struct-ref.expanded.rs +++ b/tests/expand/naming/tuple_struct-ref.expanded.rs @@ -19,6 +19,9 @@ struct TupleStruct(#[pin] T, U); clippy::missing_docs_in_private_items, clippy::ref_option_ref )] +/**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ +#[non_exhaustive] struct ProjRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -51,6 +54,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -60,6 +66,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -73,6 +81,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> ProjRef<'pin, T, U> { diff --git a/tests/expand/not_unpin/enum.expanded.rs b/tests/expand/not_unpin/enum.expanded.rs index 98b978c6..f2e17fe3 100644 --- a/tests/expand/not_unpin/enum.expanded.rs +++ b/tests/expand/not_unpin/enum.expanded.rs @@ -88,6 +88,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -111,6 +113,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { diff --git a/tests/expand/not_unpin/struct.expanded.rs b/tests/expand/not_unpin/struct.expanded.rs index 5734fc28..d076ce2f 100644 --- a/tests/expand/not_unpin/struct.expanded.rs +++ b/tests/expand/not_unpin/struct.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,6 +55,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -62,6 +70,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/not_unpin/tuple_struct.expanded.rs b/tests/expand/not_unpin/tuple_struct.expanded.rs index ff486324..bb50fb0b 100644 --- a/tests/expand/not_unpin/tuple_struct.expanded.rs +++ b/tests/expand/not_unpin/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -43,6 +49,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -56,6 +64,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/pinned_drop/enum.expanded.rs b/tests/expand/pinned_drop/enum.expanded.rs index ad6122a4..4eca7296 100644 --- a/tests/expand/pinned_drop/enum.expanded.rs +++ b/tests/expand/pinned_drop/enum.expanded.rs @@ -89,6 +89,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -112,6 +114,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { diff --git a/tests/expand/pinned_drop/struct.expanded.rs b/tests/expand/pinned_drop/struct.expanded.rs index d485563e..7e8ab5b4 100644 --- a/tests/expand/pinned_drop/struct.expanded.rs +++ b/tests/expand/pinned_drop/struct.expanded.rs @@ -32,6 +32,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -40,6 +43,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -50,6 +56,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -63,6 +71,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/pinned_drop/tuple_struct.expanded.rs b/tests/expand/pinned_drop/tuple_struct.expanded.rs index e13baf50..ad4cf23d 100644 --- a/tests/expand/pinned_drop/tuple_struct.expanded.rs +++ b/tests/expand/pinned_drop/tuple_struct.expanded.rs @@ -28,6 +28,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -35,6 +38,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -44,6 +50,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -57,6 +65,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/project_replace/enum.expanded.rs b/tests/expand/project_replace/enum.expanded.rs index cb13c71f..630499e2 100644 --- a/tests/expand/project_replace/enum.expanded.rs +++ b/tests/expand/project_replace/enum.expanded.rs @@ -57,6 +57,7 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Enum>, and a replacement. Replace the pinned Enum and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/project_replace/struct.expanded.rs b/tests/expand/project_replace/struct.expanded.rs index 48a9552d..4394c608 100644 --- a/tests/expand/project_replace/struct.expanded.rs +++ b/tests/expand/project_replace/struct.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -47,6 +53,8 @@ const _: () = { unpinned: &'pin (U), } #[allow(dead_code, clippy::missing_docs_in_private_items)] + ///A projection that own a Struct. + #[non_exhaustive] struct __StructProjectionOwned { pinned: ::pin_project::__private::PhantomData, unpinned: U, @@ -54,6 +62,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -67,6 +77,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { @@ -80,6 +92,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut Struct>, and a replacement. Replace the pinned Struct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/project_replace/tuple_struct.expanded.rs b/tests/expand/project_replace/tuple_struct.expanded.rs index 37a98c14..253e7b5c 100644 --- a/tests/expand/project_replace/tuple_struct.expanded.rs +++ b/tests/expand/project_replace/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -41,6 +47,8 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items)] + ///A projection that own a TupleStruct. + #[non_exhaustive] struct __TupleStructProjectionOwned( ::pin_project::__private::PhantomData, U, @@ -48,6 +56,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -61,6 +71,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { @@ -74,6 +86,7 @@ const _: () = { } #[allow(dead_code)] #[inline] + ///Take a Pin<&mut TupleStruct>, and a replacement. Replace the pinned TupleStruct and return an owning projection fn project_replace( self: _pin_project::__private::Pin<&mut Self>, __replacement: Self, diff --git a/tests/expand/pub/enum.expanded.rs b/tests/expand/pub/enum.expanded.rs index 6f197f5d..3bffe9eb 100644 --- a/tests/expand/pub/enum.expanded.rs +++ b/tests/expand/pub/enum.expanded.rs @@ -88,6 +88,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ pub(crate) fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -111,6 +113,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ pub(crate) fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { diff --git a/tests/expand/pub/struct.expanded.rs b/tests/expand/pub/struct.expanded.rs index 2cbbf0f8..0142dc90 100644 --- a/tests/expand/pub/struct.expanded.rs +++ b/tests/expand/pub/struct.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] pub(crate) struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { pub unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] pub(crate) struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,6 +55,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ pub(crate) fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -62,6 +70,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ pub(crate) fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/pub/tuple_struct.expanded.rs b/tests/expand/pub/tuple_struct.expanded.rs index 21cff190..515179ae 100644 --- a/tests/expand/pub/tuple_struct.expanded.rs +++ b/tests/expand/pub/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] pub(crate) struct __TupleStructProjection<'pin, T, U>( pub ::pin_project::__private::Pin<&'pin mut (T)>, pub &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] pub(crate) struct __TupleStructProjectionRef<'pin, T, U>( pub ::pin_project::__private::Pin<&'pin (T)>, pub &'pin (U), @@ -43,6 +49,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ pub(crate) fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -56,6 +64,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ pub(crate) fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/expand/unsafe_unpin/enum.expanded.rs b/tests/expand/unsafe_unpin/enum.expanded.rs index 9520e69d..74adfcc0 100644 --- a/tests/expand/unsafe_unpin/enum.expanded.rs +++ b/tests/expand/unsafe_unpin/enum.expanded.rs @@ -88,6 +88,8 @@ const _: () = { impl Enum { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> EnumProj<'pin, T, U> { @@ -111,6 +113,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Enum> and project it, aka return a Enum-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> EnumProjRef<'pin, T, U> { diff --git a/tests/expand/unsafe_unpin/struct.expanded.rs b/tests/expand/unsafe_unpin/struct.expanded.rs index 213fcd4a..084e769a 100644 --- a/tests/expand/unsafe_unpin/struct.expanded.rs +++ b/tests/expand/unsafe_unpin/struct.expanded.rs @@ -31,6 +31,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected Struct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjection<'pin, T, U> where Struct: 'pin, @@ -39,6 +42,9 @@ const _: () = { unpinned: &'pin mut (U), } #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected Struct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& Struct> directly rather than this struct*/ + #[non_exhaustive] struct __StructProjectionRef<'pin, T, U> where Struct: 'pin, @@ -49,6 +55,8 @@ const _: () = { impl Struct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __StructProjection<'pin, T, U> { @@ -62,6 +70,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& Struct> and project it, aka return a Struct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __StructProjectionRef<'pin, T, U> { diff --git a/tests/expand/unsafe_unpin/tuple_struct.expanded.rs b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs index 3ca82acd..5f7b58e2 100644 --- a/tests/expand/unsafe_unpin/tuple_struct.expanded.rs +++ b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs @@ -27,6 +27,9 @@ const _: () = { #[allow(unused_extern_crates)] extern crate pin_project as _pin_project; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)] + /**A projected TupleStruct. Obtained trough the .project() method, useful to access the fields. +You should however consider passing around a Pin<&mut TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjection<'pin, T, U>( ::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U), @@ -34,6 +37,9 @@ const _: () = { where TupleStruct: 'pin; #[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)] + /**A immutably projected TupleStruct. Obtained trough the .project_ref() method, useful to access the fields. +You should consider passing around a Pin<& TupleStruct> directly rather than this struct*/ + #[non_exhaustive] struct __TupleStructProjectionRef<'pin, T, U>( ::pin_project::__private::Pin<&'pin (T)>, &'pin (U), @@ -43,6 +49,8 @@ const _: () = { impl TupleStruct { #[allow(dead_code)] #[inline] + /**Take a Pin<&mut TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) mutable reference to the corresponding field of Self*/ fn project<'pin>( self: _pin_project::__private::Pin<&'pin mut Self>, ) -> __TupleStructProjection<'pin, T, U> { @@ -56,6 +64,8 @@ const _: () = { } #[allow(dead_code)] #[inline] + /**Take a Pin<& TupleStruct> and project it, aka return a TupleStruct-like data structure with fields of the same name, + each being a (pinned if necessary) reference to the corresponding field of Self*/ fn project_ref<'pin>( self: _pin_project::__private::Pin<&'pin Self>, ) -> __TupleStructProjectionRef<'pin, T, U> { diff --git a/tests/include/basic-safe-part.rs b/tests/include/basic-safe-part.rs index 7f216f6e..3c9cf997 100644 --- a/tests/include/basic-safe-part.rs +++ b/tests/include/basic-safe-part.rs @@ -273,3 +273,15 @@ pub enum NotUnpinEnum { /// Unit variant. Unit, } + +/// Testing pub doc +#[::pin_project::pin_project(pub project = PubStructProj)] +#[derive(Debug)] +#[allow(clippy::exhaustive_structs)] // for the type itself +pub struct PubStruct { + /// Pinned field. + #[pin] + pub pinned: T, + /// Unpinned field. + pub unpinned: U, +} diff --git a/tests/ui/pin_project/invalid.rs b/tests/ui/pin_project/invalid.rs index 9867ce65..705949b4 100644 --- a/tests/ui/pin_project/invalid.rs +++ b/tests/ui/pin_project/invalid.rs @@ -193,6 +193,18 @@ mod pin_project_argument { enum ProjectReplaceEnum { V(#[pin] ()), } + + #[pin_project(pub)] //~ Error `pub` can only be used on project, project_ref or named project_replace. + struct Pub1(#[pin] ()); + + #[pin_project(pub Unpin)] //~ Error unexpected argument: Unpin + struct Pub2(#[pin] ()); + + #[pin_project(pub project_replace)] //~ Error `pub` can only be used on project, project_ref or named project_replace. + struct Pub3(#[pin] ()); + + #[pin_project(pub project_replace = Pub4ProjReplace, pub project = Pub4Proj)] // Ok + struct Pub4(#[pin] ()); } mod pin_project_conflict_naming { diff --git a/tests/ui/pin_project/invalid.stderr b/tests/ui/pin_project/invalid.stderr index 01f1bf82..d4b88130 100644 --- a/tests/ui/pin_project/invalid.stderr +++ b/tests/ui/pin_project/invalid.stderr @@ -250,115 +250,133 @@ error: `project_replace` argument requires a value when used on enums 192 | #[pin_project(project_replace)] //~ ERROR `project_replace` argument requires a value when used on enums | ^^^^^^^^^^^^^^^ +error: `pub` can only be used on project, project_ref or named project_replace + --> tests/ui/pin_project/invalid.rs:197:19 + | +197 | #[pin_project(pub)] //~ Error `pub` can only be used on project, project_ref or named project_replace. + | ^^^ + +error: unexpected argument: Unpin + --> tests/ui/pin_project/invalid.rs:200:23 + | +200 | #[pin_project(pub Unpin)] //~ Error unexpected argument: Unpin + | ^^^^^ + +error: `pub` can only be used on project, project_ref or named project_replace. + --> tests/ui/pin_project/invalid.rs:203:19 + | +203 | #[pin_project(pub project_replace)] //~ Error `pub` can only be used on project, project_ref or named project_replace. + | ^^^ + error: name `OrigAndProj` is the same as the original type name - --> tests/ui/pin_project/invalid.rs:201:29 + --> tests/ui/pin_project/invalid.rs:213:29 | -201 | #[pin_project(project = OrigAndProj)] //~ ERROR name `OrigAndProj` is the same as the original type name +213 | #[pin_project(project = OrigAndProj)] //~ ERROR name `OrigAndProj` is the same as the original type name | ^^^^^^^^^^^ error: name `OrigAndProjRef` is the same as the original type name - --> tests/ui/pin_project/invalid.rs:204:33 + --> tests/ui/pin_project/invalid.rs:216:33 | -204 | #[pin_project(project_ref = OrigAndProjRef)] //~ ERROR name `OrigAndProjRef` is the same as the original type name +216 | #[pin_project(project_ref = OrigAndProjRef)] //~ ERROR name `OrigAndProjRef` is the same as the original type name | ^^^^^^^^^^^^^^ error: name `OrigAndProjOwn` is the same as the original type name - --> tests/ui/pin_project/invalid.rs:207:37 + --> tests/ui/pin_project/invalid.rs:219:37 | -207 | #[pin_project(project_replace = OrigAndProjOwn)] //~ ERROR name `OrigAndProjOwn` is the same as the original type name +219 | #[pin_project(project_replace = OrigAndProjOwn)] //~ ERROR name `OrigAndProjOwn` is the same as the original type name | ^^^^^^^^^^^^^^ error: name `A` is already specified by `project` argument - --> tests/ui/pin_project/invalid.rs:210:46 + --> tests/ui/pin_project/invalid.rs:222:46 | -210 | #[pin_project(project = A, project_ref = A)] //~ ERROR name `A` is already specified by `project` argument +222 | #[pin_project(project = A, project_ref = A)] //~ ERROR name `A` is already specified by `project` argument | ^ error: name `A` is already specified by `project` argument - --> tests/ui/pin_project/invalid.rs:213:50 + --> tests/ui/pin_project/invalid.rs:225:50 | -213 | #[pin_project(project = A, project_replace = A)] //~ ERROR name `A` is already specified by `project` argument +225 | #[pin_project(project = A, project_replace = A)] //~ ERROR name `A` is already specified by `project` argument | ^ error: name `A` is already specified by `project_ref` argument - --> tests/ui/pin_project/invalid.rs:216:54 + --> tests/ui/pin_project/invalid.rs:228:54 | -216 | #[pin_project(project_ref = A, project_replace = A)] //~ ERROR name `A` is already specified by `project_ref` argument +228 | #[pin_project(project_ref = A, project_replace = A)] //~ ERROR name `A` is already specified by `project_ref` argument | ^ error: duplicate #[pin_project] attribute - --> tests/ui/pin_project/invalid.rs:224:5 + --> tests/ui/pin_project/invalid.rs:236:5 | -224 | #[pin_project] //~ ERROR duplicate #[pin_project] attribute +236 | #[pin_project] //~ ERROR duplicate #[pin_project] attribute | ^^^^^^^^^^^^^^ error: #[pin_project] attribute may not be used on structs with zero fields - --> tests/ui/pin_project/invalid.rs:232:19 + --> tests/ui/pin_project/invalid.rs:244:19 | -232 | struct Struct {} //~ ERROR may not be used on structs with zero fields +244 | struct Struct {} //~ ERROR may not be used on structs with zero fields | ^^ error: #[pin_project] attribute may not be used on structs with zero fields - --> tests/ui/pin_project/invalid.rs:235:23 + --> tests/ui/pin_project/invalid.rs:247:23 | -235 | struct TupleStruct(); //~ ERROR may not be used on structs with zero fields +247 | struct TupleStruct(); //~ ERROR may not be used on structs with zero fields | ^^ error: #[pin_project] attribute may not be used on structs with zero fields - --> tests/ui/pin_project/invalid.rs:238:12 + --> tests/ui/pin_project/invalid.rs:250:12 | -238 | struct UnitStruct; //~ ERROR may not be used on structs with zero fields +250 | struct UnitStruct; //~ ERROR may not be used on structs with zero fields | ^^^^^^^^^^ error: #[pin_project] attribute may not be used on enums without variants - --> tests/ui/pin_project/invalid.rs:241:20 + --> tests/ui/pin_project/invalid.rs:253:20 | -241 | enum EnumEmpty {} //~ ERROR may not be used on enums without variants +253 | enum EnumEmpty {} //~ ERROR may not be used on enums without variants | ^^ error: #[pin_project] attribute may not be used on enums with discriminants - --> tests/ui/pin_project/invalid.rs:245:13 + --> tests/ui/pin_project/invalid.rs:257:13 | -245 | V = 2, //~ ERROR may not be used on enums with discriminants +257 | V = 2, //~ ERROR may not be used on enums with discriminants | ^ error: #[pin_project] attribute may not be used on enums with zero fields - --> tests/ui/pin_project/invalid.rs:250:9 + --> tests/ui/pin_project/invalid.rs:262:9 | -250 | / Unit, //~ ERROR may not be used on enums with zero fields -251 | | Tuple(), -252 | | Struct {}, +262 | / Unit, //~ ERROR may not be used on enums with zero fields +263 | | Tuple(), +264 | | Struct {}, | |__________________^ error: #[pin_project] attribute may only be used on structs or enums - --> tests/ui/pin_project/invalid.rs:256:5 + --> tests/ui/pin_project/invalid.rs:268:5 | -256 | / union Union { -257 | | //~^ ERROR may only be used on structs or enums -258 | | f: (), -259 | | } +268 | / union Union { +269 | | //~^ ERROR may only be used on structs or enums +270 | | f: (), +271 | | } | |_____^ error: #[pin_project] attribute may only be used on structs or enums - --> tests/ui/pin_project/invalid.rs:262:5 + --> tests/ui/pin_project/invalid.rs:274:5 | -262 | impl Impl {} //~ ERROR may only be used on structs or enums +274 | impl Impl {} //~ ERROR may only be used on structs or enums | ^^^^^^^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> tests/ui/pin_project/invalid.rs:270:12 + --> tests/ui/pin_project/invalid.rs:282:12 | -270 | #[repr(packed)] +282 | #[repr(packed)] | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> tests/ui/pin_project/invalid.rs:274:12 + --> tests/ui/pin_project/invalid.rs:286:12 | -274 | #[repr(packed)] +286 | #[repr(packed)] | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types - --> tests/ui/pin_project/invalid.rs:278:12 + --> tests/ui/pin_project/invalid.rs:290:12 | -278 | #[repr(packed)] +290 | #[repr(packed)] | ^^^^^^