From fd9e5acba8a3366a03f3ec910b36ba66619c06d1 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 10 Oct 2019 07:32:45 +0900 Subject: [PATCH 1/2] Use doc(inline) on re-export of project_ref --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 20e40f0c..10b16072 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,7 +59,7 @@ pub use pin_project_internal::pinned_drop; #[doc(inline)] pub use pin_project_internal::project; -#[doc(hidden)] +#[doc(inline)] pub use pin_project_internal::project_ref; /// A trait used for custom implementations of [`Unpin`]. From 654f1eecd5debdf8df3d321f64fb920d199b50d1 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 10 Oct 2019 07:36:48 +0900 Subject: [PATCH 2/2] Rename some utility functions --- pin-project-internal/src/pin_project/attribute.rs | 8 ++++---- pin-project-internal/src/pin_project/derive.rs | 14 ++++++-------- pin-project-internal/src/project.rs | 8 ++++---- pin-project-internal/src/utils.rs | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/pin-project-internal/src/pin_project/attribute.rs b/pin-project-internal/src/pin_project/attribute.rs index 547c1476..ad0e297f 100644 --- a/pin-project-internal/src/pin_project/attribute.rs +++ b/pin-project-internal/src/pin_project/attribute.rs @@ -7,8 +7,8 @@ use syn::{ }; use crate::utils::{ - self, collect_cfg, determine_visibility, proj_ident, proj_lifetime_name, Immutable, Mutable, - Variants, VecExt, DEFAULT_LIFETIME_NAME, + collect_cfg, determine_lifetime_name, determine_visibility, insert_lifetime, proj_ident, + Immutable, Mutable, Variants, VecExt, DEFAULT_LIFETIME_NAME, }; use super::PIN; @@ -133,7 +133,7 @@ impl Context { } let mut lifetime_name = String::from(DEFAULT_LIFETIME_NAME); - proj_lifetime_name(&mut lifetime_name, &generics.params); + determine_lifetime_name(&mut lifetime_name, &generics.params); let lifetime = Lifetime::new(&lifetime_name, Span::call_site()); Ok(Self { @@ -151,7 +151,7 @@ impl Context { /// Creates the generics of projected type. fn proj_generics(&self) -> Generics { let mut generics = self.generics.clone(); - utils::proj_generics(&mut generics, self.lifetime.clone()); + insert_lifetime(&mut generics, self.lifetime.clone()); generics } diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index 2a130924..004399fe 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -2,7 +2,9 @@ use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote}; use syn::{parse::Nothing, *}; -use crate::utils::{self, proj_lifetime_name, Variants, VecExt, DEFAULT_LIFETIME_NAME}; +use crate::utils::{ + determine_lifetime_name, insert_lifetime, Variants, VecExt, DEFAULT_LIFETIME_NAME, +}; use super::PIN; @@ -44,7 +46,7 @@ struct DeriveContext { impl DeriveContext { fn new(ident: Ident, vis: Visibility, generics: Generics) -> Self { let mut lifetime_name = String::from(DEFAULT_LIFETIME_NAME); - proj_lifetime_name(&mut lifetime_name, &generics.params); + determine_lifetime_name(&mut lifetime_name, &generics.params); let lifetime = Lifetime::new(&lifetime_name, Span::call_site()); Self { ident, vis, generics, lifetime, pinned_fields: Vec::new() } @@ -53,7 +55,7 @@ impl DeriveContext { /// Creates the generics of projected type. fn proj_generics(&self) -> Generics { let mut generics = self.generics.clone(); - utils::proj_generics(&mut generics, self.lifetime.clone()); + insert_lifetime(&mut generics, self.lifetime.clone()); generics } @@ -94,11 +96,7 @@ impl DeriveContext { } }; - let struct_ident = if cfg!(proc_macro_def_site) { - format_ident!("UnpinStruct{}", orig_ident, span = make_span()) - } else { - format_ident!("__UnpinStruct{}", orig_ident) - }; + let struct_ident = format_ident!("UnpinStruct{}", orig_ident, span = make_span()); // Generate a field in our new struct for every // pinned field in the original type. diff --git a/pin-project-internal/src/project.rs b/pin-project-internal/src/project.rs index 5193e550..d83b9922 100644 --- a/pin-project-internal/src/project.rs +++ b/pin-project-internal/src/project.rs @@ -7,7 +7,7 @@ use syn::{ }; use crate::utils::{ - proj_generics, proj_ident, proj_lifetime_name, Mutability, Mutable, VecExt, + determine_lifetime_name, insert_lifetime, proj_ident, Mutability, Mutable, VecExt, DEFAULT_LIFETIME_NAME, }; @@ -141,14 +141,14 @@ fn replace_item_impl(item: &mut ItemImpl, mutability: Mutability) { replace_ident(ident, mutability); let mut lifetime_name = String::from(DEFAULT_LIFETIME_NAME); - proj_lifetime_name(&mut lifetime_name, &item.generics.params); + determine_lifetime_name(&mut lifetime_name, &item.generics.params); item.items .iter_mut() .filter_map(|i| if let ImplItem::Method(i) = i { Some(i) } else { None }) - .for_each(|item| proj_lifetime_name(&mut lifetime_name, &item.sig.generics.params)); + .for_each(|item| determine_lifetime_name(&mut lifetime_name, &item.sig.generics.params)); let lifetime = Lifetime::new(&lifetime_name, Span::call_site()); - proj_generics(&mut item.generics, syn::parse_quote!(#lifetime)); + insert_lifetime(&mut item.generics, lifetime.clone()); match arguments { PathArguments::None => { diff --git a/pin-project-internal/src/utils.rs b/pin-project-internal/src/utils.rs index 00997030..4d32bd0c 100644 --- a/pin-project-internal/src/utils.rs +++ b/pin-project-internal/src/utils.rs @@ -27,7 +27,7 @@ pub(crate) fn proj_ident(ident: &Ident, mutability: Mutability) -> Ident { } /// Determines the lifetime names. Ensure it doesn't overlap with any existing lifetime names. -pub(crate) fn proj_lifetime_name( +pub(crate) fn determine_lifetime_name( lifetime_name: &mut String, generics: &Punctuated, ) { @@ -46,8 +46,8 @@ pub(crate) fn proj_lifetime_name( } } -/// Creates the generics of projected type from the generics of the original type. -pub(crate) fn proj_generics(generics: &mut Generics, lifetime: Lifetime) { +/// Inserts a `lifetime` at position `0` of `generics.params`. +pub(crate) fn insert_lifetime(generics: &mut Generics, lifetime: Lifetime) { if generics.lt_token.is_none() { generics.lt_token = Some(token::Lt::default()) }