aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2020-10-26 16:54:29 -0700
committerChih-Hung Hsieh <chh@google.com>2020-10-26 16:57:40 -0700
commit127364b149c24623fd15786790a98af3b5355389 (patch)
tree55ba197683b0a0093a2767fcb1f576490157f8a1 /examples
parentc112e35face1579eba180108bda3da10b61d9926 (diff)
downloadpin-project-127364b149c24623fd15786790a98af3b5355389.tar.gz
Upgrade rust/crates/pin-project to 1.0.1
* Add missing patches, needed by external_updater Test: make Test: tools/external_updater/updater.sh update --refresh --keep_date rust/crates/pin-project Change-Id: I3738561830ce97903036460713eb3b74700b889e
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md11
-rw-r--r--examples/enum-default-expanded.rs53
-rw-r--r--examples/not_unpin-expanded.rs82
-rw-r--r--examples/pinned_drop-expanded.rs75
-rw-r--r--examples/project_replace-expanded.rs94
-rw-r--r--examples/struct-default-expanded.rs97
-rw-r--r--examples/unsafe_unpin-expanded.rs76
7 files changed, 220 insertions, 268 deletions
diff --git a/examples/README.md b/examples/README.md
index 94f49b5..3f0d87e 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -14,22 +14,25 @@
* [example](unsafe_unpin.rs)
* [generated code](unsafe_unpin-expanded.rs)
- * [`UnsafeUnpin` documentation](https://docs.rs/pin-project/0.4/pin_project/trait.UnsafeUnpin.html)
+ * [`UnsafeUnpin` documentation](https://docs.rs/pin-project/1/pin_project/trait.UnsafeUnpin.html)
### Manual implementation of `Drop` by `#[pinned_drop]`
* [example](pinned_drop.rs)
* [generated code](pinned_drop-expanded.rs)
- * [`#[pinned_drop]` documentation](https://docs.rs/pin-project/0.4/pin_project/attr.pinned_drop.html)
+ * [`#[pinned_drop]` documentation](https://docs.rs/pin-project/1/pin_project/attr.pinned_drop.html)
### `project_replace()` method
* [example](project_replace.rs)
* [generated code](project_replace-expanded.rs)
- * [`project_replace()` documentation](https://docs.rs/pin-project/0.4/pin_project/attr.pin_project.html#project_replace)
+ * [`project_replace()` documentation](https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#project_replace)
### Ensure `!Unpin` by `#[pin_project(!Unpin)]`
* [example](not_unpin.rs)
* [generated code](not_unpin-expanded.rs)
- * [`!Unpin` documentation](https://docs.rs/pin-project/0.4/pin_project/attr.pin_project.html#unpin)
+ * [`!Unpin` documentation](https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin)
+
+Note: These generated code examples are the little simplified version of the actual generated code.
+See [expansion tests](../tests/expand/README.md) if you want to see the exact version of the actual generated code.
diff --git a/examples/enum-default-expanded.rs b/examples/enum-default-expanded.rs
index cea3ae5..f234b51 100644
--- a/examples/enum-default-expanded.rs
+++ b/examples/enum-default-expanded.rs
@@ -14,20 +14,17 @@
// fn main() {}
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::just_underscores_and_digits)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes, clippy::just_underscores_and_digits)]
use pin_project::pin_project;
+// #[pin_project(project = EnumProj)]
enum Enum<T, U> {
Pinned(/* #[pin] */ T),
Unpinned(U),
}
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
enum EnumProj<'pin, T, U>
where
Enum<T, U>: 'pin,
@@ -35,23 +32,13 @@ where
Pinned(::pin_project::__private::Pin<&'pin mut (T)>),
Unpinned(&'pin mut (U)),
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-enum __EnumProjectionRef<'pin, T, U>
-where
- Enum<T, U>: 'pin,
-{
- Pinned(::pin_project::__private::Pin<&'pin (T)>),
- Unpinned(&'pin (U)),
-}
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ // When `#[pin_project]` is used on enums, only named projection types and
+ // methods are generated because there is no way to access variants of
+ // projected types without naming it.
+ // (When `#[pin_project]` is used on structs, both methods are always generated.)
+
impl<T, U> Enum<T, U> {
fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -65,18 +52,6 @@ const _: () = {
}
}
}
- fn project_ref<'pin>(
- self: ::pin_project::__private::Pin<&'pin Self>,
- ) -> __EnumProjectionRef<'pin, T, U> {
- unsafe {
- match self.get_ref() {
- Enum::Pinned(_0) => __EnumProjectionRef::Pinned(
- ::pin_project::__private::Pin::new_unchecked(_0),
- ),
- Enum::Unpinned(_0) => __EnumProjectionRef::Unpinned(_0),
- }
- }
- }
}
// Automatically create the appropriate conditional `Unpin` implementation.
@@ -94,15 +69,23 @@ const _: () = {
__Enum<'pin, T, U>: ::pin_project::__private::Unpin
{
}
- unsafe impl<T, U> ::pin_project::UnsafeUnpin for Enum<T, U> {}
+ // A dummy impl of `UnsafeUnpin`, to ensure that the user cannot implement it.
+ #[doc(hidden)]
+ unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum<T, U> where
+ __Enum<'pin, T, U>: ::pin_project::__private::Unpin
+ {
+ }
// Ensure that enum does not implement `Drop`.
//
// See ./struct-default-expanded.rs for details.
trait EnumMustNotImplDrop {}
- #[allow(clippy::drop_bounds)]
+ #[allow(clippy::drop_bounds, drop_bounds)]
impl<T: ::pin_project::__private::Drop> EnumMustNotImplDrop for T {}
impl<T, U> EnumMustNotImplDrop for Enum<T, U> {}
+ // A dummy impl of `PinnedDrop`, to ensure that users don't accidentally
+ // write a non-functional `PinnedDrop` impls.
+ #[doc(hidden)]
impl<T, U> ::pin_project::__private::PinnedDrop for Enum<T, U> {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
diff --git a/examples/not_unpin-expanded.rs b/examples/not_unpin-expanded.rs
index fdfe5a2..aa5209d 100644
--- a/examples/not_unpin-expanded.rs
+++ b/examples/not_unpin-expanded.rs
@@ -18,46 +18,34 @@
// }
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::no_effect)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes)]
use pin_project::pin_project;
+// #[pin_project(!Unpin)]
pub struct Struct<T, U> {
// #[pin]
pinned: T,
unpinned: U,
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjection<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
- unpinned: &'pin mut (U),
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjectionRef<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin (T)>,
- unpinned: &'pin (U),
-}
-
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ pub(crate) struct __StructProjection<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
+ unpinned: &'pin mut (U),
+ }
+ pub(crate) struct __StructProjectionRef<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin (T)>,
+ unpinned: &'pin (U),
+ }
+
impl<T, U> Struct<T, U> {
pub(crate) fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -83,6 +71,17 @@ const _: () = {
}
}
+ // Ensure that it's impossible to use pin projections on a #[repr(packed)]
+ // struct.
+ //
+ // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
+ // for details.
+ #[forbid(safe_packed_borrows)]
+ fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
+ let _ = &this.pinned;
+ let _ = &this.unpinned;
+ }
+
// Create `Unpin` impl that has trivial `Unpin` bounds.
//
// See https://github.com/taiki-e/pin-project/issues/102#issuecomment-540472282
@@ -98,29 +97,26 @@ const _: () = {
// impls, we emit one ourselves. If the user ends up writing an `UnsafeUnpin`
// impl, they'll get a "conflicting implementations of trait" error when
// coherence checks are run.
- unsafe impl<T, U> ::pin_project::UnsafeUnpin for Struct<T, U> {}
+ #[doc(hidden)]
+ unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct<T, U> where
+ ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>:
+ ::pin_project::__private::Unpin
+ {
+ }
// Ensure that struct does not implement `Drop`.
//
// See ./struct-default-expanded.rs for details.
trait StructMustNotImplDrop {}
- #[allow(clippy::drop_bounds)]
+ #[allow(clippy::drop_bounds, drop_bounds)]
impl<T: ::pin_project::__private::Drop> StructMustNotImplDrop for T {}
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.
+ #[doc(hidden)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
-
- // Ensure that it's impossible to use pin projections on a #[repr(packed)]
- // struct.
- //
- // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
- // for details.
- #[deny(safe_packed_borrows)]
- fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
- &val.pinned;
- &val.unpinned;
- }
};
fn main() {
diff --git a/examples/pinned_drop-expanded.rs b/examples/pinned_drop-expanded.rs
index 8f295e9..ad22c0b 100644
--- a/examples/pinned_drop-expanded.rs
+++ b/examples/pinned_drop-expanded.rs
@@ -21,47 +21,35 @@
// fn main() {}
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::no_effect)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes)]
use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;
+// #[pin_project(PinnedDrop)]
pub struct Struct<'a, T> {
was_dropped: &'a mut bool,
// #[pin]
field: T,
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjection<'pin, 'a, T>
-where
- Struct<'a, T>: 'pin,
-{
- was_dropped: &'pin mut (&'a mut bool),
- field: ::pin_project::__private::Pin<&'pin mut (T)>,
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjectionRef<'pin, 'a, T>
-where
- Struct<'a, T>: 'pin,
-{
- was_dropped: &'pin (&'a mut bool),
- field: ::pin_project::__private::Pin<&'pin (T)>,
-}
-
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ pub(crate) struct __StructProjection<'pin, 'a, T>
+ where
+ Struct<'a, T>: 'pin,
+ {
+ was_dropped: &'pin mut (&'a mut bool),
+ field: ::pin_project::__private::Pin<&'pin mut (T)>,
+ }
+ pub(crate) struct __StructProjectionRef<'pin, 'a, T>
+ where
+ Struct<'a, T>: 'pin,
+ {
+ was_dropped: &'pin (&'a mut bool),
+ field: ::pin_project::__private::Pin<&'pin (T)>,
+ }
+
impl<'a, T> Struct<'a, T> {
pub(crate) fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -87,6 +75,17 @@ const _: () = {
}
}
+ // Ensure that it's impossible to use pin projections on a #[repr(packed)]
+ // struct.
+ //
+ // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
+ // for details.
+ #[forbid(safe_packed_borrows)]
+ fn __assert_not_repr_packed<'a, T>(this: &Struct<'a, T>) {
+ let _ = &this.was_dropped;
+ let _ = &this.field;
+ }
+
impl<'a, T> ::pin_project::__private::Drop for Struct<'a, T> {
fn drop(&mut self) {
// Safety - we're in 'drop', so we know that 'self' will
@@ -114,17 +113,11 @@ const _: () = {
__Struct<'pin, 'a, T>: ::pin_project::__private::Unpin
{
}
- unsafe impl<'a, T> ::pin_project::UnsafeUnpin for Struct<'a, T> {}
-
- // Ensure that it's impossible to use pin projections on a #[repr(packed)]
- // struct.
- //
- // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
- // for details.
- #[deny(safe_packed_borrows)]
- fn __assert_not_repr_packed<'a, T>(val: &Struct<'a, T>) {
- &val.was_dropped;
- &val.field;
+ // A dummy impl of `UnsafeUnpin`, to ensure that the user cannot implement it.
+ #[doc(hidden)]
+ unsafe impl<'pin, 'a, T> ::pin_project::UnsafeUnpin for Struct<'a, T> where
+ __Struct<'pin, 'a, T>: ::pin_project::__private::Unpin
+ {
}
};
diff --git a/examples/project_replace-expanded.rs b/examples/project_replace-expanded.rs
index 16f47b7..ec00d41 100644
--- a/examples/project_replace-expanded.rs
+++ b/examples/project_replace-expanded.rs
@@ -15,54 +15,38 @@
// fn main() {}
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::no_effect)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes)]
use pin_project::pin_project;
+// #[pin_project(project_replace)]
struct Struct<T, U> {
// #[pin]
pinned: T,
unpinned: U,
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
-struct __StructProjection<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
- unpinned: &'pin mut (U),
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-struct __StructProjectionRef<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin (T)>,
- unpinned: &'pin (U),
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(unreachable_pub)]
-#[allow(single_use_lifetimes)]
-struct __StructProjectionOwned<T, U> {
- pinned: ::pin_project::__private::PhantomData<T>,
- unpinned: U,
-}
-
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ struct __StructProjection<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
+ unpinned: &'pin mut (U),
+ }
+ struct __StructProjectionRef<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin (T)>,
+ unpinned: &'pin (U),
+ }
+ struct __StructProjectionOwned<T, U> {
+ pinned: ::pin_project::__private::PhantomData<T>,
+ unpinned: U,
+ }
+
impl<T, U> Struct<T, U> {
fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -122,6 +106,17 @@ const _: () = {
}
}
+ // Ensure that it's impossible to use pin projections on a #[repr(packed)]
+ // struct.
+ //
+ // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
+ // for details.
+ #[forbid(safe_packed_borrows)]
+ fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
+ let _ = &this.pinned;
+ let _ = &this.unpinned;
+ }
+
// Automatically create the appropriate conditional `Unpin` implementation.
//
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53.
@@ -137,29 +132,26 @@ const _: () = {
__Struct<'pin, T, U>: ::pin_project::__private::Unpin
{
}
- unsafe impl<T, U> ::pin_project::UnsafeUnpin for Struct<T, U> {}
+ // A dummy impl of `UnsafeUnpin`, to ensure that the user cannot implement it.
+ #[doc(hidden)]
+ unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct<T, U> where
+ __Struct<'pin, T, U>: ::pin_project::__private::Unpin
+ {
+ }
// Ensure that struct does not implement `Drop`.
//
// See ./struct-default-expanded.rs for details.
trait StructMustNotImplDrop {}
- #[allow(clippy::drop_bounds)]
+ #[allow(clippy::drop_bounds, drop_bounds)]
impl<T: ::pin_project::__private::Drop> StructMustNotImplDrop for T {}
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.
+ #[doc(hidden)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
-
- // Ensure that it's impossible to use pin projections on a #[repr(packed)]
- // struct.
- //
- // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
- // for details.
- #[deny(safe_packed_borrows)]
- fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
- &val.pinned;
- &val.unpinned;
- }
};
fn main() {}
diff --git a/examples/struct-default-expanded.rs b/examples/struct-default-expanded.rs
index ff160ce..3d0e4ab 100644
--- a/examples/struct-default-expanded.rs
+++ b/examples/struct-default-expanded.rs
@@ -15,46 +15,34 @@
// fn main() {}
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::no_effect)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes)]
use pin_project::pin_project;
+// #[pin_project]
struct Struct<T, U> {
// #[pin]
pinned: T,
unpinned: U,
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
-struct __StructProjection<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
- unpinned: &'pin mut (U),
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-struct __StructProjectionRef<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin (T)>,
- unpinned: &'pin (U),
-}
-
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ struct __StructProjection<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
+ unpinned: &'pin mut (U),
+ }
+ struct __StructProjectionRef<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin (T)>,
+ unpinned: &'pin (U),
+ }
+
impl<T, U> Struct<T, U> {
fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -80,6 +68,26 @@ const _: () = {
}
}
+ // Ensure that it's impossible to use pin projections on a #[repr(packed)]
+ // struct.
+ //
+ // Taking a reference to a packed field is unsafe, and applying
+ // #[forbid(safe_packed_borrows)] makes sure that doing this without
+ // an 'unsafe' block (which we deliberately do not generate)
+ // is a hard error.
+ //
+ // If the struct ends up having #[repr(packed)] applied somehow,
+ // this will generate an (unfriendly) error message. Under all reasonable
+ // circumstances, we'll detect the #[repr(packed)] attribute, and generate
+ // a much nicer error above.
+ //
+ // See https://github.com/taiki-e/pin-project/pull/34 for more details.
+ #[forbid(safe_packed_borrows)]
+ fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
+ let _ = &this.pinned;
+ let _ = &this.unpinned;
+ }
+
// Automatically create the appropriate conditional `Unpin` implementation.
//
// Basically this is equivalent to the following code:
@@ -123,7 +131,11 @@ const _: () = {
// impls, we emit one ourselves. If the user ends up writing an `UnsafeUnpin`
// impl, they'll get a "conflicting implementations of trait" error when
// coherence checks are run.
- unsafe impl<T, U> ::pin_project::UnsafeUnpin for Struct<T, U> {}
+ #[doc(hidden)]
+ unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct<T, U> where
+ __Struct<'pin, T, U>: ::pin_project::__private::Unpin
+ {
+ }
// Ensure that struct does not implement `Drop`.
//
@@ -131,34 +143,15 @@ const _: () = {
// then apply to your type, causing a compile-time error due to
// the conflict with the second impl.
trait StructMustNotImplDrop {}
- #[allow(clippy::drop_bounds)]
+ #[allow(clippy::drop_bounds, drop_bounds)]
impl<T: ::pin_project::__private::Drop> StructMustNotImplDrop for T {}
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.
+ #[doc(hidden)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
-
- // Ensure that it's impossible to use pin projections on a #[repr(packed)]
- // struct.
- //
- // Taking a reference to a packed field is unsafe, and applying
- // #[deny(safe_packed_borrows)] makes sure that doing this without
- // an 'unsafe' block (which we deliberately do not generate)
- // is a hard error.
- //
- // If the struct ends up having #[repr(packed)] applied somehow,
- // this will generate an (unfriendly) error message. Under all reasonable
- // circumstances, we'll detect the #[repr(packed)] attribute, and generate
- // a much nicer error above.
- //
- // See https://github.com/taiki-e/pin-project/pull/34 for more details.
- #[deny(safe_packed_borrows)]
- fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
- &val.pinned;
- &val.unpinned;
- }
};
fn main() {}
diff --git a/examples/unsafe_unpin-expanded.rs b/examples/unsafe_unpin-expanded.rs
index e55b740..2ea1f37 100644
--- a/examples/unsafe_unpin-expanded.rs
+++ b/examples/unsafe_unpin-expanded.rs
@@ -17,46 +17,34 @@
// fn main() {}
// ```
-#![allow(dead_code, unused_imports, unused_parens)]
-#![allow(clippy::no_effect)]
+#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)]
+#![allow(clippy::needless_lifetimes)]
use pin_project::{pin_project, UnsafeUnpin};
+// #[pin_project(UnsafeUnpin)]
pub struct Struct<T, U> {
// #[pin]
pinned: T,
unpinned: U,
}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::mut_mut)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjection<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
- unpinned: &'pin mut (U),
-}
-#[doc(hidden)]
-#[allow(dead_code)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::type_repetition_in_bounds)]
-pub(crate) struct __StructProjectionRef<'pin, T, U>
-where
- Struct<T, U>: 'pin,
-{
- pinned: ::pin_project::__private::Pin<&'pin (T)>,
- unpinned: &'pin (U),
-}
-
-#[doc(hidden)]
-#[allow(non_upper_case_globals)]
-#[allow(single_use_lifetimes)]
-#[allow(clippy::used_underscore_binding)]
const _: () = {
+ pub(crate) struct __StructProjection<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
+ unpinned: &'pin mut (U),
+ }
+ pub(crate) struct __StructProjectionRef<'pin, T, U>
+ where
+ Struct<T, U>: 'pin,
+ {
+ pinned: ::pin_project::__private::Pin<&'pin (T)>,
+ unpinned: &'pin (U),
+ }
+
impl<T, U> Struct<T, U> {
pub(crate) fn project<'pin>(
self: ::pin_project::__private::Pin<&'pin mut Self>,
@@ -82,6 +70,18 @@ const _: () = {
}
}
+ // Ensure that it's impossible to use pin projections on a #[repr(packed)]
+ // struct.
+ //
+ // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
+ // for details.
+ #[forbid(safe_packed_borrows)]
+ fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
+ let _ = &this.pinned;
+ let _ = &this.unpinned;
+ }
+
+ // Implement `Unpin` via `UnsafeUnpin`.
impl<'pin, T, U> ::pin_project::__private::Unpin for Struct<T, U> where
::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin
{
@@ -91,23 +91,15 @@ const _: () = {
//
// See ./struct-default-expanded.rs for details.
trait StructMustNotImplDrop {}
- #[allow(clippy::drop_bounds)]
+ #[allow(clippy::drop_bounds, drop_bounds)]
impl<T: ::pin_project::__private::Drop> StructMustNotImplDrop for T {}
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.
+ #[doc(hidden)]
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
-
- // Ensure that it's impossible to use pin projections on a #[repr(packed)]
- // struct.
- //
- // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
- // for details.
- #[deny(safe_packed_borrows)]
- fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
- &val.pinned;
- &val.unpinned;
- }
};
unsafe impl<T: Unpin, U> UnsafeUnpin for Struct<T, U> {}