diff options
Diffstat (limited to 'examples/struct-default-expanded.rs')
-rw-r--r-- | examples/struct-default-expanded.rs | 97 |
1 files changed, 45 insertions, 52 deletions
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() {} |