Skip to content

Commit

Permalink
Merge #77
Browse files Browse the repository at this point in the history
77: Move automatic generation of Unpin implementation to proc-macro-derive r=taiki-e a=taiki-e

To generate the correct `Unpin` implementation, we need to collect the
types of the pinned fields. However, since proc-macro-attribute is
applied before cfg, we cannot be collecting field types at this timing.
So instead of generating the `Unpin` implementation here, we need to
delegate automatic generation of the `Unpin` implementation to
proc-macro-derive.

Fixes #68

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Sep 7, 2019
2 parents 69f8014 + 6a0d419 commit 3e82552
Show file tree
Hide file tree
Showing 42 changed files with 1,455 additions and 804 deletions.
9 changes: 7 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
parameters:
toolchain: nightly
name: nightly
cross: true

- job: compiletest
pool:
Expand All @@ -49,7 +50,9 @@ jobs:
toolchain: nightly
- script: |
cargo clean
RUSTFLAGS='--cfg compiletest --cfg pin_project_show_unpin_struct' cargo test -p pin-project --all-features --test compiletest
cargo test -p pin-project --all-features --test compiletest
env:
RUSTFLAGS: -Dwarnings --cfg compiletest --cfg pin_project_show_unpin_struct
displayName: compiletest
- job: clippy
Expand Down Expand Up @@ -122,5 +125,7 @@ jobs:
parameters:
toolchain: nightly
- script: |
RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all --all-features
cargo doc --no-deps --all --all-features
env:
RUSTDOCFLAGS: -Dwarnings
displayName: cargo doc
12 changes: 10 additions & 2 deletions ci/azure-test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
parameters:
vmImage: ubuntu-16.04
cmd: test

jobs:
- job: ${{ parameters.name }}
strategy:
matrix:
Linux:
vmImage: ubuntu-16.04
${{ if parameters.cross }}:
MacOS:
vmImage: macOS-10.13
Windows:
vmImage: vs2017-win2016
pool:
vmImage: ${{ parameters.vmImage }}
vmImage: $(vmImage)

steps:
- template: azure-install-rust.yml
Expand Down
5 changes: 5 additions & 0 deletions compiletest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# A script to run compile tests with the same condition that pin-project executes with CI.

rm -rf target/debug/deps/libpin_project* && RUSTFLAGS='--cfg compiletest --cfg pin_project_show_unpin_struct' cargo test -p pin-project --all-features --test compiletest
20 changes: 12 additions & 8 deletions examples/struct-default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ impl<'_outer_pin, T, U> __StructProjectionTrait<'_outer_pin, T, U>
{
fn project<'_pin>(&'_pin mut self) -> __StructProjection<'_pin, T, U> {
unsafe {
let this = self.as_mut().get_unchecked_mut();
let Struct { pinned, unpinned } = self.as_mut().get_unchecked_mut();
__StructProjection {
pinned: ::core::pin::Pin::new_unchecked(&mut this.pinned),
unpinned: &mut this.unpinned,
pinned: ::core::pin::Pin::new_unchecked(pinned),
unpinned: unpinned,
}
}
}
fn project_into(self) -> __StructProjection<'_outer_pin, T, U> {
unsafe {
let this = self.get_unchecked_mut();
let Struct { pinned, unpinned } = self.get_unchecked_mut();
__StructProjection {
pinned: ::core::pin::Pin::new_unchecked(&mut this.pinned),
unpinned: &mut this.unpinned,
pinned: ::core::pin::Pin::new_unchecked(pinned),
unpinned: unpinned,
}
}
}
Expand Down Expand Up @@ -91,8 +91,12 @@ 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() {}
16 changes: 13 additions & 3 deletions pin-project-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ use syn::parse::Nothing;
/// [`pinned_drop`]: ./attr.pinned_drop.html
#[proc_macro_attribute]
pub fn pin_project(args: TokenStream, input: TokenStream) -> TokenStream {
pin_project::attribute(args.into(), input.into()).into()
let input = syn::parse_macro_input!(input);
pin_project::attribute(args.into(), input).into()
}

// TODO: Move this doc into pin-project crate when https://github.com/rust-lang/rust/pull/62855 merged.
Expand Down Expand Up @@ -372,7 +373,8 @@ pub fn pin_project(args: TokenStream, input: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
let _: Nothing = syn::parse_macro_input!(args);
pinned_drop::attribute(input.into()).into()
let input = syn::parse_macro_input!(input);
pinned_drop::attribute(&input).into()
}

// TODO: Move this doc into pin-project crate when https://github.com/rust-lang/rust/pull/62855 merged.
Expand Down Expand Up @@ -493,7 +495,15 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn project(args: TokenStream, input: TokenStream) -> TokenStream {
let _: Nothing = syn::parse_macro_input!(args);
project::attribute(input.into()).into()
let input = syn::parse_macro_input!(input);
project::attribute(input).into()
}

#[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()
}

#[cfg(feature = "renamed")]
Expand Down
Loading

0 comments on commit 3e82552

Please sign in to comment.