Skip to content

Commit

Permalink
Merge #135
Browse files Browse the repository at this point in the history
135: Move most of the processing to proc-macro-derive r=taiki-e a=taiki-e

To generate the correct `Unpin` implementation and the projection methods, we need to collect the types of the pinned fields.  However, since proc-macro-attribute is applied before `#[cfg]` and `#[cfg_attr]` on fields, we cannot be collecting field types properly at this timing. So instead of generating the `Unpin` implementation and the projection methods here, delegate their processing to proc-macro-derive.

#77 moved only the automatic generation of `Unpin` implementation to proc-macro-derive but found that it could not support `#[cfg_attr]`, so this moves more processing.

See also #68 (comment).

This also adds support for the use of `#[cfg]` on tuple structs and tuple variants.

Closes #123

Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Oct 14, 2019
2 parents ff8e9bd + b1bdd9a commit 4c494e7
Show file tree
Hide file tree
Showing 38 changed files with 1,167 additions and 1,025 deletions.
8 changes: 2 additions & 6 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ fn __unpin_scope_Foo() {
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: &Foo<'a, T>) {
{
&val.was_dropped;
}
{
&val.field;
}
&val.was_dropped;
&val.field;
}

fn main() {}
8 changes: 2 additions & 6 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ impl<T, U> StructMustNotImplDrop for Struct<T, U> {}
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Struct<T, U>(val: &Struct<T, U>) {
{
&val.pinned;
}
{
&val.unpinned;
}
&val.pinned;
&val.unpinned;
}

fn main() {}
8 changes: 2 additions & 6 deletions examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ impl<T, U> FooMustNotImplDrop for Foo<T, U> {}
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Foo<T, U>(val: &Foo<T, U>) {
{
&val.pinned;
}
{
&val.unpinned;
}
&val.pinned;
&val.unpinned;
}

fn main() {}
11 changes: 5 additions & 6 deletions pin-project-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ use utils::{Immutable, Mutable};
/// [`pinned_drop`]: ./attr.pinned_drop.html
#[proc_macro_attribute]
pub fn pin_project(args: TokenStream, input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
pin_project::attribute(args.into(), input).into()
pin_project::attribute(&args.into(), input.into()).into()
}

/// An attribute for annotating an impl block that implements [`Drop`].
Expand Down Expand Up @@ -538,9 +537,9 @@ pub fn project_ref(args: TokenStream, input: TokenStream) -> TokenStream {
project::attribute(&args.into(), input, Immutable).into()
}

/// An internal helper macro.
#[doc(hidden)]
#[proc_macro_derive(__PinProjectAutoImplUnpin, attributes(pin))]
pub fn derive_unpin(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
pin_project::derive(input).into()
#[proc_macro_derive(__PinProjectInternalDerive, attributes(pin))]
pub fn __pin_project_internal_derive(input: TokenStream) -> TokenStream {
pin_project::derive(input.into()).into()
}
Loading

0 comments on commit 4c494e7

Please sign in to comment.