Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overwriting the name of core crate #199

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions examples/enum-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,41 @@ enum __EnumProjection<'pin, T, U>
where
Enum<T, U>: 'pin,
{
Pinned(::core::pin::Pin<&'pin mut (T)>),
Pinned(::pin_project::__reexport::pin::Pin<&'pin mut (T)>),
Unpinned(&'pin mut (U)),
}
#[allow(dead_code)] // This lint warns unused fields/variants.
enum __EnumProjectionRef<'pin, T, U>
where
Enum<T, U>: 'pin,
{
Pinned(::core::pin::Pin<&'pin (T)>),
Pinned(::pin_project::__reexport::pin::Pin<&'pin (T)>),
Unpinned(&'pin (U)),
}

#[allow(non_upper_case_globals)]
const __SCOPE_Enum: () = {
impl<T, U> Enum<T, U> {
fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __EnumProjection<'pin, T, U> {
fn project<'pin>(
self: ::pin_project::__reexport::pin::Pin<&'pin mut Self>,
) -> __EnumProjection<'pin, T, U> {
unsafe {
match self.get_unchecked_mut() {
Enum::Pinned(_0) => {
__EnumProjection::Pinned(::core::pin::Pin::new_unchecked(_0))
}
Enum::Pinned(_0) => __EnumProjection::Pinned(
::pin_project::__reexport::pin::Pin::new_unchecked(_0),
),
Enum::Unpinned(_0) => __EnumProjection::Unpinned(_0),
}
}
}
fn project_ref<'pin>(
self: ::core::pin::Pin<&'pin Self>,
self: ::pin_project::__reexport::pin::Pin<&'pin Self>,
) -> __EnumProjectionRef<'pin, T, U> {
unsafe {
match self.get_ref() {
Enum::Pinned(_0) => {
__EnumProjectionRef::Pinned(::core::pin::Pin::new_unchecked(_0))
}
Enum::Pinned(_0) => __EnumProjectionRef::Pinned(
::pin_project::__reexport::pin::Pin::new_unchecked(_0),
),
Enum::Unpinned(_0) => __EnumProjectionRef::Unpinned(_0),
}
}
Expand All @@ -76,20 +78,22 @@ const __SCOPE_Enum: () = {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__field0: T,
}
impl<'pin, T, U> ::core::marker::Unpin for Enum<T, U> where __Enum<'pin, T, U>: ::core::marker::Unpin
{}
impl<'pin, T, U> ::pin_project::__reexport::marker::Unpin for Enum<T, U> where
__Enum<'pin, T, U>: ::pin_project::__reexport::marker::Unpin
{
}

// Ensure that enum does not implement `Drop`.
//
// See ./struct-default-expanded.rs for details.
trait EnumMustNotImplDrop {}
#[allow(clippy::drop_bounds)]
impl<T: ::core::ops::Drop> EnumMustNotImplDrop for T {}
impl<T: ::pin_project::__reexport::ops::Drop> EnumMustNotImplDrop for T {}
#[allow(single_use_lifetimes)]
impl<T, U> EnumMustNotImplDrop for Enum<T, U> {}
#[allow(single_use_lifetimes)]
impl<T, U> ::pin_project::__private::PinnedDrop for Enum<T, U> {
unsafe fn drop(self: ::core::pin::Pin<&mut Self>) {}
unsafe fn drop(self: ::pin_project::__reexport::pin::Pin<&mut Self>) {}
}

// We don't need to check for `#[repr(packed)]`,
Expand Down
56 changes: 31 additions & 25 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
// use std::pin::Pin;
//
// #[pin_project(PinnedDrop)]
// pub struct Foo<'a, T> {
// pub struct Struct<'a, T> {
// was_dropped: &'a mut bool,
// #[pin]
// field: T,
// }
//
// #[pinned_drop]
// fn drop_foo<T>(mut this: Pin<&mut Foo<'_, T>>) {
// fn drop_Struct<T>(mut this: Pin<&mut Struct<'_, T>>) {
// **this.project().was_dropped = true;
// }
//
Expand All @@ -26,57 +26,63 @@
use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;

pub struct Foo<'a, T> {
pub struct Struct<'a, T> {
was_dropped: &'a mut bool,
// #[pin]
field: T,
}

#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[allow(dead_code)] // This lint warns unused fields/variants.
pub(crate) struct __FooProjection<'pin, 'a, T>
pub(crate) struct __StructProjection<'pin, 'a, T>
where
Foo<'a, T>: 'pin,
Struct<'a, T>: 'pin,
{
was_dropped: &'pin mut (&'a mut bool),
field: ::core::pin::Pin<&'pin mut (T)>,
field: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
}
#[allow(dead_code)] // This lint warns unused fields/variants.
pub(crate) struct __FooProjectionRef<'pin, 'a, T>
pub(crate) struct __StructProjectionRef<'pin, 'a, T>
where
Foo<'a, T>: 'pin,
Struct<'a, T>: 'pin,
{
was_dropped: &'pin (&'a mut bool),
field: ::core::pin::Pin<&'pin (T)>,
field: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
}

#[allow(non_upper_case_globals)]
const __SCOPE_Foo: () = {
impl<'a, T> Foo<'a, T> {
const __SCOPE_Struct: () = {
impl<'a, T> Struct<'a, T> {
pub(crate) fn project<'pin>(
self: ::core::pin::Pin<&'pin mut Self>,
) -> __FooProjection<'pin, 'a, T> {
self: ::pin_project::__reexport::pin::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, 'a, T> {
unsafe {
let Self { was_dropped, field } = self.get_unchecked_mut();
__FooProjection { was_dropped, field: ::core::pin::Pin::new_unchecked(field) }
__StructProjection {
was_dropped,
field: ::pin_project::__reexport::pin::Pin::new_unchecked(field),
}
}
}
pub(crate) fn project_ref<'pin>(
self: ::core::pin::Pin<&'pin Self>,
) -> __FooProjectionRef<'pin, 'a, T> {
self: ::pin_project::__reexport::pin::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, 'a, T> {
unsafe {
let Self { was_dropped, field } = self.get_ref();
__FooProjectionRef { was_dropped, field: ::core::pin::Pin::new_unchecked(field) }
__StructProjectionRef {
was_dropped,
field: ::pin_project::__reexport::pin::Pin::new_unchecked(field),
}
}
}
}

#[allow(single_use_lifetimes)]
impl<'a, T> ::core::ops::Drop for Foo<'a, T> {
impl<'a, T> ::pin_project::__reexport::ops::Drop for Struct<'a, T> {
fn drop(&mut self) {
// Safety - we're in 'drop', so we know that 'self' will
// never move again.
let pinned_self = unsafe { ::core::pin::Pin::new_unchecked(self) };
let pinned_self = unsafe { ::pin_project::__reexport::pin::Pin::new_unchecked(self) };
// We call `pinned_drop` only once. Since `PinnedDrop::drop`
// is an unsafe method and a private API, it is never called again in safe
// code *unless the user uses a maliciously crafted macro*.
Expand All @@ -97,11 +103,11 @@ const __SCOPE_Foo: () = {
//
// Users can implement `Drop` safely using `#[pinned_drop]`.
// **Do not call or implement this trait directly.**
impl<T> ::pin_project::__private::PinnedDrop for Foo<'_, T> {
impl<T> ::pin_project::__private::PinnedDrop for Struct<'_, T> {
// Since calling it twice on the same object would be UB,
// this method is unsafe.
unsafe fn drop(self: Pin<&mut Self>) {
fn __drop_inner<T>(__self: Pin<&mut Foo<'_, T>>) {
fn __drop_inner<T>(__self: Pin<&mut Struct<'_, T>>) {
**__self.project().was_dropped = true;
}
__drop_inner(self);
Expand All @@ -112,13 +118,13 @@ const __SCOPE_Foo: () = {
//
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
// for details.
pub struct __Foo<'pin, 'a, T> {
pub struct __Struct<'pin, 'a, T> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T)>,
__field0: T,
__lifetime0: &'a (),
}
impl<'pin, 'a, T> ::core::marker::Unpin for Foo<'a, T> where
__Foo<'pin, 'a, T>: ::core::marker::Unpin
impl<'pin, 'a, T> ::pin_project::__reexport::marker::Unpin for Struct<'a, T> where
__Struct<'pin, 'a, T>: ::pin_project::__reexport::marker::Unpin
{
}

Expand All @@ -128,7 +134,7 @@ const __SCOPE_Foo: () = {
// for details.
#[allow(single_use_lifetimes)]
#[deny(safe_packed_borrows)]
fn __assert_not_repr_packed<'a, T>(val: &Foo<'a, T>) {
fn __assert_not_repr_packed<'a, T>(val: &Struct<'a, T>) {
&val.was_dropped;
&val.field;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/pinned_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;

#[pin_project(PinnedDrop)]
pub struct Foo<'a, T> {
pub struct Struct<'a, T> {
was_dropped: &'a mut bool,
#[pin]
field: T,
}

#[pinned_drop]
impl<T> PinnedDrop for Foo<'_, T> {
impl<T> PinnedDrop for Struct<'_, T> {
fn drop(self: Pin<&mut Self>) {
**self.project().was_dropped = true;
}
Expand Down
28 changes: 18 additions & 10 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,41 @@ struct __StructProjection<'pin, T, U>
where
Struct<T, U>: 'pin,
{
pinned: ::core::pin::Pin<&'pin mut (T)>,
pinned: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
unpinned: &'pin mut (U),
}
#[allow(dead_code)] // This lint warns unused fields/variants.
struct __StructProjectionRef<'pin, T, U>
where
Struct<T, U>: 'pin,
{
pinned: ::core::pin::Pin<&'pin (T)>,
pinned: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
unpinned: &'pin (U),
}

#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __StructProjection<'pin, T, U> {
fn project<'pin>(
self: ::pin_project::__reexport::pin::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
unsafe {
let Self { pinned, unpinned } = self.get_unchecked_mut();
__StructProjection { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned }
__StructProjection {
pinned: ::pin_project::__reexport::pin::Pin::new_unchecked(pinned),
unpinned,
}
}
}
fn project_ref<'pin>(
self: ::core::pin::Pin<&'pin Self>,
self: ::pin_project::__reexport::pin::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
unsafe {
let Self { pinned, unpinned } = self.get_ref();
__StructProjectionRef { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned }
__StructProjectionRef {
pinned: ::pin_project::__reexport::pin::Pin::new_unchecked(pinned),
unpinned,
}
}
}
}
Expand Down Expand Up @@ -92,8 +100,8 @@ const __SCOPE_Struct: () = {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>,
__field0: T,
}
impl<'pin, T, U> ::core::marker::Unpin for Struct<T, U> where
__Struct<'pin, T, U>: ::core::marker::Unpin
impl<'pin, T, U> ::pin_project::__reexport::marker::Unpin for Struct<T, U> where
__Struct<'pin, T, U>: ::pin_project::__reexport::marker::Unpin
{
}

Expand All @@ -104,14 +112,14 @@ const __SCOPE_Struct: () = {
// the conflict with the second impl.
trait StructMustNotImplDrop {}
#[allow(clippy::drop_bounds)]
impl<T: ::core::ops::Drop> StructMustNotImplDrop for T {}
impl<T: ::pin_project::__reexport::ops::Drop> StructMustNotImplDrop for T {}
#[allow(single_use_lifetimes)]
impl<T, U> StructMustNotImplDrop for Struct<T, U> {}
// A dummy impl of `PinnedDrop`, to ensure that users don't accidentally
// write a non-functional `PinnedDrop` impls.
#[allow(single_use_lifetimes)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
unsafe fn drop(self: ::core::pin::Pin<&mut Self>) {}
unsafe fn drop(self: ::pin_project::__reexport::pin::Pin<&mut Self>) {}
}

// Ensure that it's impossible to use pin projections on a #[repr(packed)] struct.
Expand Down
Loading