diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/pin-project-lite/src/lib.rs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/pin-project-lite/src/lib.rs')
-rw-r--r-- | vendor/pin-project-lite/src/lib.rs | 116 |
1 files changed, 100 insertions, 16 deletions
diff --git a/vendor/pin-project-lite/src/lib.rs b/vendor/pin-project-lite/src/lib.rs index 89e56928d..6ec2021ea 100644 --- a/vendor/pin-project-lite/src/lib.rs +++ b/vendor/pin-project-lite/src/lib.rs @@ -98,13 +98,14 @@ description of the compile error. ### Different: No support for custom Unpin implementation -pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin]. +pin-project supports this by [`UnsafeUnpin`][unsafe-unpin]. (`!Unpin` is supported by both [pin-project][not-unpin] and [pin-project-lite][not-unpin-lite].) ### Different: No support for tuple structs and tuple variants pin-project supports this. [not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin +[not-unpin-lite]: https://docs.rs/pin-project-lite/0.2/pin_project_lite/macro.pin_project.html#unpin [pin-project]: https://github.com/taiki-e/pin-project [unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin @@ -295,8 +296,22 @@ pin-project supports this. /// /// # `!Unpin` /// -/// If you want to ensure that [`Unpin`] is not implemented, use `#[pin]` -/// attribute for a [`PhantomPinned`] field. +/// If you want to make sure `Unpin` is not implemented, use the `#[project(!Unpin)]` +/// attribute. +/// +/// ``` +/// use pin_project_lite::pin_project; +/// +/// pin_project! { +/// #[project(!Unpin)] +/// struct Struct<T> { +/// #[pin] +/// field: T, +/// } +/// } +/// ``` +/// +/// This is equivalent to using `#[pin]` attribute for a [`PhantomPinned`] field. /// /// ```rust /// use std::marker::PhantomPinned; @@ -306,13 +321,14 @@ pin-project supports this. /// pin_project! { /// struct Struct<T> { /// field: T, -/// #[pin] // <------ This `#[pin]` is required to make `Struct` to `!Unpin`. +/// #[pin] /// _pin: PhantomPinned, /// } /// } /// ``` /// -/// Note that using [`PhantomPinned`] without `#[pin]` attribute has no effect. +/// Note that using [`PhantomPinned`] without `#[pin]` or `#[project(!Unpin)]` +/// attribute has no effect. /// /// [`PhantomPinned`]: core::marker::PhantomPinned /// [`Pin::as_mut`]: core::pin::Pin::as_mut @@ -322,7 +338,7 @@ pin-project supports this. macro_rules! pin_project { ($($tt:tt)*) => { $crate::__pin_project_internal! { - [][][][] + [][][][][] $($tt)* } }; @@ -344,6 +360,7 @@ macro_rules! __pin_project_expand { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$($proj_not_unpin_mark:ident)?] [$proj_vis:vis] [$(#[$attrs:meta])* $vis:vis $struct_ty_ident:ident $ident:ident] [$($def_generics:tt)*] @@ -351,7 +368,7 @@ macro_rules! __pin_project_expand { { $($body_data:tt)* } - $(impl $($pinned_drop:tt)*)? + $($(#[$drop_impl_attrs:meta])* impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_reconstruct! { [$(#[$attrs])* $vis $struct_ty_ident $ident] @@ -393,13 +410,14 @@ macro_rules! __pin_project_expand { $crate::__pin_project_constant! { [$(#[$attrs])* $vis $struct_ty_ident $ident] [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$($proj_not_unpin_mark)?] [$proj_vis] [$($def_generics)*] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $($body_data)* } - $(impl $($pinned_drop)*)? + $($(#[$drop_impl_attrs])* impl $($pinned_drop)*)? } }; } @@ -410,6 +428,7 @@ macro_rules! __pin_project_constant { ( [$(#[$attrs:meta])* $vis:vis struct $ident:ident] [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$($proj_not_unpin_mark:ident)?] [$proj_vis:vis] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] @@ -419,7 +438,7 @@ macro_rules! __pin_project_constant { $field_vis:vis $field:ident: $field_ty:ty ),+ $(,)? } - $(impl $($pinned_drop:tt)*)? + $($(#[$drop_impl_attrs:meta])* impl $($pinned_drop:tt)*)? ) => { #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 @@ -497,6 +516,7 @@ macro_rules! __pin_project_constant { } $crate::__pin_project_make_unpin_impl! { + [$($proj_not_unpin_mark)?] [$vis $ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $( @@ -509,7 +529,7 @@ macro_rules! __pin_project_constant { $crate::__pin_project_make_drop_impl! { [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] - $(impl $($pinned_drop)*)? + $($(#[$drop_impl_attrs])* impl $($pinned_drop)*)? } // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. @@ -546,6 +566,7 @@ macro_rules! __pin_project_constant { ( [$(#[$attrs:meta])* $vis:vis enum $ident:ident] [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$($proj_not_unpin_mark:ident)?] [$proj_vis:vis] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] @@ -560,7 +581,7 @@ macro_rules! __pin_project_constant { })? ),+ $(,)? } - $(impl $($pinned_drop:tt)*)? + $($(#[$drop_impl_attrs:meta])* impl $($pinned_drop:tt)*)? ) => { #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 // This lint warns of `clippy::*` generated by external macros. @@ -622,6 +643,7 @@ macro_rules! __pin_project_constant { } $crate::__pin_project_make_unpin_impl! { + [$($proj_not_unpin_mark)?] [$vis $ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] $( @@ -638,7 +660,7 @@ macro_rules! __pin_project_constant { $crate::__pin_project_make_drop_impl! { [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] - $(impl $($pinned_drop)*)? + $($(#[$drop_impl_attrs])* impl $($pinned_drop)*)? } // We don't need to check for '#[repr(packed)]', @@ -783,6 +805,7 @@ macro_rules! __pin_project_make_proj_ty_body { [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] [$($body_data:tt)+] ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 // This lint warns of `clippy::*` generated by external macros. @@ -876,6 +899,7 @@ macro_rules! __pin_project_make_proj_replace_ty_body { [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] [$($body_data:tt)+] ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) @@ -954,6 +978,7 @@ macro_rules! __pin_project_struct_make_proj_method { ),+ } ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[inline] $proj_vis fn $method_ident<'__pin>( self: $crate::__private::Pin<&'__pin $($mut)? Self>, @@ -988,6 +1013,7 @@ macro_rules! __pin_project_struct_make_proj_replace_method { ),+ } ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[inline] $proj_vis fn project_replace( self: $crate::__private::Pin<&mut Self>, @@ -1036,6 +1062,7 @@ macro_rules! __pin_project_enum_make_proj_method { ),+ } ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[inline] $proj_vis fn $method_ident<'__pin>( self: $crate::__private::Pin<&'__pin $($mut)? Self>, @@ -1080,6 +1107,7 @@ macro_rules! __pin_project_enum_make_proj_replace_method { ),+ } ) => { + #[doc(hidden)] // Workaround for rustc bug: see https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1671540180 for more. #[inline] $proj_vis fn project_replace( self: $crate::__private::Pin<&mut Self>, @@ -1118,6 +1146,7 @@ macro_rules! __pin_project_enum_make_proj_replace_method { #[macro_export] macro_rules! __pin_project_make_unpin_impl { ( + [] [$vis:vis $ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] $($field:tt)* @@ -1162,6 +1191,23 @@ macro_rules! __pin_project_make_unpin_impl { { } }; + ( + [$proj_not_unpin_mark:ident] + [$vis:vis $ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + $($field:tt)* + ) => { + #[doc(hidden)] + impl <'__pin, $($impl_generics)*> $crate::__private::Unpin for $ident <$($ty_generics)*> + where + ( + ::core::marker::PhantomData<&'__pin ()>, + ::core::marker::PhantomPinned, + ): $crate::__private::Unpin + $(, $($where_clause)*)? + { + } + } } #[doc(hidden)] @@ -1170,6 +1216,7 @@ macro_rules! __pin_project_make_drop_impl { ( [$_ident:ident] [$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)*)?] + $(#[$drop_impl_attrs:meta])* impl $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? $( $generics:ident @@ -1186,11 +1233,13 @@ macro_rules! __pin_project_make_drop_impl { ),* $(,)? )? { + $(#[$drop_fn_attrs:meta])* fn drop($($arg:ident)+: Pin<&mut Self>) { $($tt:tt)* } } ) => { + $(#[$drop_impl_attrs])* impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics @@ -1207,6 +1256,7 @@ macro_rules! __pin_project_make_drop_impl { ),* )? { + $(#[$drop_fn_attrs])* fn drop(&mut self) { // Implementing `__DropInner::__drop_inner` is safe, but calling it is not safe. // This is because destructors can be called multiple times in safe code and @@ -1360,6 +1410,7 @@ macro_rules! __pin_project_internal { [] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] #[project = $proj_mut_ident:ident] @@ -1369,6 +1420,7 @@ macro_rules! __pin_project_internal { [$proj_mut_ident] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$( ! $proj_not_unpin_mark)?] [$($attrs)*] $($tt)* } @@ -1378,6 +1430,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident:ident)?] [] [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] #[project_ref = $proj_ref_ident:ident] @@ -1387,6 +1440,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident)?] [$proj_ref_ident] [$($proj_replace_ident)?] + [$( ! $proj_not_unpin_mark)?] [$($attrs)*] $($tt)* } @@ -1396,6 +1450,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] #[project_replace = $proj_replace_ident:ident] @@ -1405,6 +1460,27 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$proj_replace_ident] + [$( ! $proj_not_unpin_mark)?] + [$($attrs)*] + $($tt)* + } + }; + // parsing !Unpin + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [] + [$($attrs:tt)*] + + #[project( ! $proj_not_unpin_mark:ident)] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [ ! $proj_not_unpin_mark] [$($attrs)*] $($tt)* } @@ -1415,6 +1491,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] #[$($attr:tt)*] @@ -1424,6 +1501,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$( ! $proj_not_unpin_mark)?] [$($attrs)* #[$($attr)*]] $($tt)* } @@ -1434,6 +1512,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] pub $struct_ty_ident:ident $ident:ident $($tt:tt)* @@ -1442,6 +1521,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$($proj_not_unpin_mark)?] [$($attrs)*] [pub $struct_ty_ident $ident pub(crate)] $($tt)* @@ -1451,6 +1531,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] [$($attrs:tt)*] $vis:vis $struct_ty_ident:ident $ident:ident $($tt:tt)* @@ -1459,6 +1540,7 @@ macro_rules! __pin_project_internal { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$($proj_not_unpin_mark)?] [$($attrs)*] [$vis $struct_ty_ident $ident $vis] $($tt)* @@ -1473,8 +1555,9 @@ macro_rules! __pin_project_parse_generics { [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$($proj_not_unpin_mark:ident)?] [$($attrs:tt)*] - [$vis:vis $struct_ty_ident:ident $ident:ident $proj_ty_vis:vis] + [$vis:vis $struct_ty_ident:ident $ident:ident $proj_vis:vis] $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? $( $generics:ident @@ -1494,13 +1577,14 @@ macro_rules! __pin_project_parse_generics { { $($body_data:tt)* } - $(impl $($pinned_drop:tt)*)? + $($(#[$drop_impl_attrs:meta])* impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_expand! { [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] - [$proj_ty_vis] + [$($proj_not_unpin_mark)?] + [$proj_vis] [$($attrs)* $vis $struct_ty_ident $ident] [$(< $( $lifetime $(: $lifetime_bound)? ,)* @@ -1528,7 +1612,7 @@ macro_rules! __pin_project_parse_generics { { $($body_data)* } - $(impl $($pinned_drop)*)? + $($(#[$drop_impl_attrs])* impl $($pinned_drop)*)? } }; } |