Skip to content

Commit

Permalink
Merge #121 #122
Browse files Browse the repository at this point in the history
121: Use doc(inline) on re-export of project_ref r=taiki-e a=taiki-e



122: Rename some utility functions r=taiki-e a=taiki-e



Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Oct 9, 2019
3 parents bea0ef8 + fd9e5ac + 654f1ee commit 4803d04
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pin-project-internal/src/pin_project/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
14 changes: 6 additions & 8 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() }
Expand All @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pin-project-internal/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions pin-project-internal/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericParam, Comma>,
) {
Expand All @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down

0 comments on commit 4803d04

Please sign in to comment.