mirror of
https://github.com/openharmony/third_party_rust_pin-project-lite.git
synced 2026-07-01 20:44:14 -04:00
Break up __pin_project_internal! into multiple rules.
By removal internal rules, this commit turns one giant macro with 47
rules into 23 macros with a small number of rules each. I find the
resulting code *much* easier to read; I found the original giant macro
quite overwhelming. The new code also needs fewer comments because the
code is clearer.
The commit also fixes some minor formatting inconsistencies, such as
always putting a space between the `!` and the `{` in a macro
invocation, and using parens instead of braces for a few matchers.
This commit is contained in:
+212
-211
@@ -306,13 +306,10 @@ macro_rules! pin_project {
|
||||
// - no useful error messages. (wontfix)
|
||||
// etc...
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_internal {
|
||||
// =============================================================================================
|
||||
// struct:main
|
||||
(@expand;
|
||||
macro_rules! __pin_project_expand {
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
@@ -325,7 +322,7 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
$(impl $($pinned_drop:tt)*)?
|
||||
) => {
|
||||
$crate::__pin_project_internal! { @reconstruct;
|
||||
$crate::__pin_project_reconstruct! {
|
||||
[$(#[$attrs])* $vis $struct_ty_ident $ident]
|
||||
[$($def_generics)*] [$($impl_generics)*]
|
||||
[$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
@@ -334,35 +331,35 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$proj_vis $struct_ty_ident $ident]
|
||||
[make_proj_field_mut]
|
||||
[__pin_project_make_proj_field_mut]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$($body_data)*
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty! {
|
||||
[$($proj_ref_ident)?]
|
||||
[$proj_vis $struct_ty_ident $ident]
|
||||
[make_proj_field_ref]
|
||||
[__pin_project_make_proj_field_ref]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$($body_data)*
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @make_proj_replace_ty;
|
||||
$crate::__pin_project_make_proj_replace_ty! {
|
||||
[$($proj_replace_ident)?]
|
||||
[$proj_vis $struct_ty_ident]
|
||||
[make_proj_field_replace]
|
||||
[__pin_project_make_proj_field_replace]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$($body_data)*
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @constant;
|
||||
$crate::__pin_project_constant! {
|
||||
[$(#[$attrs])* $vis $struct_ty_ident $ident]
|
||||
[$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?]
|
||||
[$proj_vis]
|
||||
@@ -374,7 +371,12 @@ macro_rules! __pin_project_internal {
|
||||
$(impl $($pinned_drop)*)?
|
||||
}
|
||||
};
|
||||
(@constant;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
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_vis:vis]
|
||||
@@ -388,7 +390,6 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
$(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
|
||||
// This lint warns of `clippy::*` generated by external macros.
|
||||
@@ -397,10 +398,10 @@ macro_rules! __pin_project_internal {
|
||||
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
$crate::__pin_project_internal! { @make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty! {
|
||||
[$($proj_mut_ident)? Projection]
|
||||
[$proj_vis struct $ident]
|
||||
[make_proj_field_mut]
|
||||
[__pin_project_make_proj_field_mut]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$(
|
||||
@@ -409,10 +410,10 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty! {
|
||||
[$($proj_ref_ident)? ProjectionRef]
|
||||
[$proj_vis struct $ident]
|
||||
[make_proj_field_ref]
|
||||
[__pin_project_make_proj_field_ref]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$(
|
||||
@@ -426,7 +427,7 @@ macro_rules! __pin_project_internal {
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
$crate::__pin_project_internal! { @struct=>make_proj_method;
|
||||
$crate::__pin_project_struct_make_proj_method! {
|
||||
[$($proj_mut_ident)? Projection]
|
||||
[$proj_vis]
|
||||
[project get_unchecked_mut mut]
|
||||
@@ -438,7 +439,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @struct=>make_proj_method;
|
||||
$crate::__pin_project_struct_make_proj_method! {
|
||||
[$($proj_ref_ident)? ProjectionRef]
|
||||
[$proj_vis]
|
||||
[project_ref get_ref]
|
||||
@@ -450,7 +451,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @struct=>make_proj_replace_method;
|
||||
$crate::__pin_project_struct_make_proj_replace_method! {
|
||||
[$($proj_replace_ident)?]
|
||||
[$proj_vis]
|
||||
[ProjectionReplace]
|
||||
@@ -464,17 +465,17 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_unpin_impl;
|
||||
$crate::__pin_project_make_unpin_impl! {
|
||||
[$vis $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_unpin_bound;
|
||||
$field: $crate::__pin_project_make_unpin_bound!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_drop_impl;
|
||||
$crate::__pin_project_make_drop_impl! {
|
||||
[$ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
$(impl $($pinned_drop)*)?
|
||||
@@ -511,9 +512,7 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
};
|
||||
};
|
||||
// =============================================================================================
|
||||
// enum:main
|
||||
(@constant;
|
||||
(
|
||||
[$(#[$attrs:meta])* $vis:vis enum $ident:ident]
|
||||
[$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?]
|
||||
[$proj_vis:vis]
|
||||
@@ -532,7 +531,6 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
$(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.
|
||||
// We allow this lint for compatibility with older compilers.
|
||||
@@ -543,7 +541,7 @@ macro_rules! __pin_project_internal {
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
$crate::__pin_project_internal! { @enum=>make_proj_method;
|
||||
$crate::__pin_project_enum_make_proj_method! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$proj_vis]
|
||||
[project get_unchecked_mut mut]
|
||||
@@ -559,7 +557,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @enum=>make_proj_method;
|
||||
$crate::__pin_project_enum_make_proj_method! {
|
||||
[$($proj_ref_ident)?]
|
||||
[$proj_vis]
|
||||
[project_ref get_ref]
|
||||
@@ -575,7 +573,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
}
|
||||
$crate::__pin_project_internal! { @enum=>make_proj_replace_method;
|
||||
$crate::__pin_project_enum_make_proj_replace_method! {
|
||||
[$($proj_replace_ident)?]
|
||||
[$proj_vis]
|
||||
[$($ty_generics)*]
|
||||
@@ -592,13 +590,13 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_unpin_impl;
|
||||
$crate::__pin_project_make_unpin_impl! {
|
||||
[$vis $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
$(
|
||||
$variant: ($(
|
||||
$(
|
||||
$crate::__pin_project_internal!(@make_unpin_bound;
|
||||
$crate::__pin_project_make_unpin_bound!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
@@ -606,7 +604,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_drop_impl;
|
||||
$crate::__pin_project_make_drop_impl! {
|
||||
[$ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
$(impl $($pinned_drop)*)?
|
||||
@@ -616,8 +614,12 @@ macro_rules! __pin_project_internal {
|
||||
// since it does not apply to enums.
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
(@reconstruct;
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_reconstruct {
|
||||
(
|
||||
[$(#[$attrs:meta])* $vis:vis struct $ident:ident]
|
||||
[$($def_generics:tt)*] [$($impl_generics:tt)*]
|
||||
[$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
@@ -638,9 +640,7 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
};
|
||||
|
||||
// reconstruct original enum type
|
||||
(@reconstruct;
|
||||
(
|
||||
[$(#[$attrs:meta])* $vis:vis enum $ident:ident]
|
||||
[$($def_generics:tt)*] [$($impl_generics:tt)*]
|
||||
[$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
@@ -671,25 +671,22 @@ macro_rules! __pin_project_internal {
|
||||
),+
|
||||
}
|
||||
};
|
||||
// macro helpers
|
||||
// ignores any projection without a projection identity
|
||||
(@make_proj_ty;
|
||||
[] // no identity given, so we ignore the projection
|
||||
$($field:tt)*
|
||||
) => {};
|
||||
// =============================================================================================
|
||||
// struct:make_proj_ty
|
||||
// if a proj_ty_ident was given, we do *not* create one with the default
|
||||
(@make_proj_ty;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_ty {
|
||||
([] $($field:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident $default_ident:ident]
|
||||
[$proj_vis:vis struct $ident:ident]
|
||||
$($field:tt)*
|
||||
) => {};
|
||||
(@make_proj_ty;
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis struct $ident:ident]
|
||||
[$make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$__pin_project_make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
@@ -697,26 +694,24 @@ macro_rules! __pin_project_internal {
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal!{@make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty_body! {
|
||||
[$proj_ty_ident]
|
||||
[$proj_vis struct $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
[
|
||||
$(
|
||||
$field_vis $field: $crate::__pin_project_internal!(@$make_proj_field;
|
||||
$field_vis $field: $crate::$__pin_project_make_proj_field!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
]
|
||||
}
|
||||
};
|
||||
// =============================================================================================
|
||||
// enum:make_proj_ty
|
||||
(@make_proj_ty;
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis enum $ident:ident]
|
||||
[$make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$__pin_project_make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$variant_attrs:meta])*
|
||||
@@ -729,15 +724,15 @@ macro_rules! __pin_project_internal {
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal!{@make_proj_ty;
|
||||
$crate::__pin_project_make_proj_ty_body! {
|
||||
[$proj_ty_ident]
|
||||
[$proj_vis enum $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
[
|
||||
$(
|
||||
$variant $({
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@$make_proj_field;
|
||||
$field: $crate::$__pin_project_make_proj_field!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
@@ -746,11 +741,15 @@ macro_rules! __pin_project_internal {
|
||||
]
|
||||
}
|
||||
};
|
||||
// construct a projected type
|
||||
(@make_proj_ty;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_ty_body {
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis $struct_ty_ident:ident $ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
[$($body_data:tt)+]
|
||||
) => {
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
@@ -770,16 +769,17 @@ macro_rules! __pin_project_internal {
|
||||
$($body_data)+
|
||||
}
|
||||
};
|
||||
// ignores make_proj_replace_ty without a projection identity
|
||||
(@make_proj_replace_ty;
|
||||
[] // no identity given, so we ignore the projection
|
||||
$($field:tt)*
|
||||
) => {};
|
||||
(@make_proj_replace_ty;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_replace_ty {
|
||||
([] $($field:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis struct]
|
||||
[$make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$__pin_project_make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
@@ -787,24 +787,24 @@ macro_rules! __pin_project_internal {
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal!{@make_proj_replace_ty;
|
||||
$crate::__pin_project_make_proj_replace_ty_body! {
|
||||
[$proj_ty_ident]
|
||||
[$proj_vis struct]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
[
|
||||
$(
|
||||
$field_vis $field: $crate::__pin_project_internal!(@$make_proj_field;
|
||||
$field_vis $field: $crate::$__pin_project_make_proj_field!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
]
|
||||
}
|
||||
};
|
||||
(@make_proj_replace_ty;
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis enum]
|
||||
[$make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$__pin_project_make_proj_field:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$variant_attrs:meta])*
|
||||
@@ -817,15 +817,15 @@ macro_rules! __pin_project_internal {
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal!{@make_proj_replace_ty;
|
||||
$crate::__pin_project_make_proj_replace_ty_body! {
|
||||
[$proj_ty_ident]
|
||||
[$proj_vis enum]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
[
|
||||
$(
|
||||
$variant $({
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@$make_proj_field;
|
||||
$field: $crate::$__pin_project_make_proj_field!(
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
@@ -834,11 +834,15 @@ macro_rules! __pin_project_internal {
|
||||
]
|
||||
}
|
||||
};
|
||||
// construct a project_replace type
|
||||
(@make_proj_replace_ty;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_replace_ty_body {
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis $struct_ty_ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
[$($body_data:tt)+]
|
||||
) => {
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
@@ -853,9 +857,13 @@ macro_rules! __pin_project_internal {
|
||||
$($body_data)+
|
||||
}
|
||||
};
|
||||
// =============================================================================================
|
||||
(@make_proj_replace_block;
|
||||
[$($proj_path: tt)+]
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_replace_block {
|
||||
(
|
||||
[$($proj_path:tt)+]
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
@@ -865,7 +873,7 @@ macro_rules! __pin_project_internal {
|
||||
) => {
|
||||
let result = $($proj_path)* {
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_replace_field_proj;
|
||||
$field: $crate::__pin_project_make_replace_field_proj!(
|
||||
$(#[$pin])? $field
|
||||
)
|
||||
),+
|
||||
@@ -873,7 +881,7 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
{
|
||||
( $(
|
||||
$crate::__pin_project_internal!(@make_unsafe_drop_in_place_guard;
|
||||
$crate::__pin_project_make_unsafe_drop_in_place_guard!(
|
||||
$(#[$pin])? $field
|
||||
),
|
||||
)* );
|
||||
@@ -881,27 +889,21 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
result
|
||||
};
|
||||
(@make_proj_replace_block;
|
||||
[$($proj_path: tt)+]
|
||||
) => {
|
||||
$($proj_path)*
|
||||
};
|
||||
([$($proj_path:tt)+]) => { $($proj_path)* };
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// struct:make_proj_method
|
||||
// this employs an ignored default strategy that ensures the identity used matches the one used in `struct=>make_proj_ty`
|
||||
(@$struct_ty_ident:ident=>make_proj_method;
|
||||
[]
|
||||
$($variant:tt)*
|
||||
) => {};
|
||||
(@struct=>make_proj_method;
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_struct_make_proj_method {
|
||||
([] $($variant:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident $_ignored_default_arg:ident]
|
||||
[$proj_vis:vis]
|
||||
[$method_ident:ident $get_method:ident $($mut:ident)?]
|
||||
[$($ty_generics:tt)*]
|
||||
$($variant:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! { @struct=>make_proj_method;
|
||||
$crate::__pin_project_struct_make_proj_method! {
|
||||
[$proj_ty_ident]
|
||||
[$proj_vis]
|
||||
[$method_ident $get_method $($mut)?]
|
||||
@@ -909,7 +911,7 @@ macro_rules! __pin_project_internal {
|
||||
$($variant)*
|
||||
}
|
||||
};
|
||||
(@struct=>make_proj_method;
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis]
|
||||
[$method_ident:ident $get_method:ident $($mut:ident)?]
|
||||
@@ -928,7 +930,7 @@ macro_rules! __pin_project_internal {
|
||||
let Self { $($field),* } = self.$get_method();
|
||||
$proj_ty_ident {
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_unsafe_field_proj;
|
||||
$field: $crate::__pin_project_make_unsafe_field_proj!(
|
||||
$(#[$pin])? $field
|
||||
)
|
||||
),+
|
||||
@@ -936,12 +938,13 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
(@$struct_ty_ident:ident=>make_proj_replace_method;
|
||||
[]
|
||||
$($field:tt)*
|
||||
) => {};
|
||||
(@struct=>make_proj_replace_method;
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_struct_make_proj_replace_method {
|
||||
([] $($field:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis]
|
||||
[$_proj_ty_ident:ident]
|
||||
@@ -966,7 +969,7 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
let Self { $($field),* } = &mut *__self_ptr;
|
||||
|
||||
$crate::__pin_project_internal!{@make_proj_replace_block;
|
||||
$crate::__pin_project_make_proj_replace_block! {
|
||||
[$proj_ty_ident]
|
||||
{
|
||||
$(
|
||||
@@ -978,9 +981,13 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
};
|
||||
// =============================================================================================
|
||||
// enum:make_proj_method
|
||||
(@enum=>make_proj_method;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_enum_make_proj_method {
|
||||
([] $($variant:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis]
|
||||
[$method_ident:ident $get_method:ident $($mut:ident)?]
|
||||
@@ -1007,8 +1014,7 @@ macro_rules! __pin_project_internal {
|
||||
})? => {
|
||||
$proj_ty_ident::$variant $({
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(
|
||||
@make_unsafe_field_proj;
|
||||
$field: $crate::__pin_project_make_unsafe_field_proj!(
|
||||
$(#[$pin])? $field
|
||||
)
|
||||
),+
|
||||
@@ -1019,7 +1025,13 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
};
|
||||
(@enum=>make_proj_replace_method;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_enum_make_proj_replace_method {
|
||||
([] $($field:tt)*) => {};
|
||||
(
|
||||
[$proj_ty_ident:ident]
|
||||
[$proj_vis:vis]
|
||||
[$($ty_generics:tt)*]
|
||||
@@ -1050,7 +1062,7 @@ macro_rules! __pin_project_internal {
|
||||
Self::$variant $({
|
||||
$($field),+
|
||||
})? => {
|
||||
$crate::__pin_project_internal!{@make_proj_replace_block;
|
||||
$crate::__pin_project_make_proj_replace_block! {
|
||||
[$proj_ty_ident :: $variant]
|
||||
$({
|
||||
$(
|
||||
@@ -1065,11 +1077,14 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
};
|
||||
// =============================================================================================
|
||||
// make_unpin_impl
|
||||
(@make_unpin_impl;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_unpin_impl {
|
||||
(
|
||||
[$vis:vis $ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
$($field:tt)*
|
||||
) => {
|
||||
// Automatically create the appropriate conditional `Unpin` implementation.
|
||||
@@ -1112,12 +1127,14 @@ macro_rules! __pin_project_internal {
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// make_drop_impl
|
||||
(@make_drop_impl;
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_drop_impl {
|
||||
(
|
||||
[$_ident:ident]
|
||||
[$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)* )?]
|
||||
[$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)*)?]
|
||||
impl $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
@@ -1199,9 +1216,9 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
}
|
||||
};
|
||||
(@make_drop_impl;
|
||||
(
|
||||
[$ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
) => {
|
||||
// Ensure that struct does not implement `Drop`.
|
||||
//
|
||||
@@ -1221,103 +1238,88 @@ macro_rules! __pin_project_internal {
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// make_unpin_bound
|
||||
(@make_unpin_bound;
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_unpin_bound {
|
||||
(#[pin] $field_ty:ty) => {
|
||||
$field_ty
|
||||
};
|
||||
(@make_unpin_bound;
|
||||
$field_ty:ty
|
||||
) => {
|
||||
($field_ty:ty) => {
|
||||
$crate::__private::AlwaysUnpin<$field_ty>
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// make_unsafe_field_proj
|
||||
(@make_unsafe_field_proj;
|
||||
#[pin]
|
||||
$field:ident
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_unsafe_field_proj {
|
||||
(#[pin] $field:ident) => {
|
||||
$crate::__private::Pin::new_unchecked($field)
|
||||
};
|
||||
(@make_unsafe_field_proj;
|
||||
$field:ident
|
||||
) => {
|
||||
($field:ident) => {
|
||||
$field
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// make_replace_field_proj
|
||||
(@make_replace_field_proj;
|
||||
#[pin]
|
||||
$field:ident
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_replace_field_proj {
|
||||
(#[pin] $field:ident) => {
|
||||
$crate::__private::PhantomData
|
||||
};
|
||||
(@make_replace_field_proj;
|
||||
$field:ident
|
||||
) => {
|
||||
($field:ident) => {
|
||||
$crate::__private::ptr::read($field)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// =============================================================================================
|
||||
// make_unsafe_drop_in_place_guard
|
||||
(@make_unsafe_drop_in_place_guard;
|
||||
#[pin]
|
||||
$field:ident
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_unsafe_drop_in_place_guard {
|
||||
(#[pin] $field:ident) => {
|
||||
$crate::__private::UnsafeDropInPlaceGuard::new($field)
|
||||
};
|
||||
(@make_unsafe_drop_in_place_guard;
|
||||
$field:ident
|
||||
) => {
|
||||
($field:ident) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// make_proj_field
|
||||
(@make_proj_field_mut;
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_field_mut {
|
||||
(#[pin] $field_ty:ty) => {
|
||||
$crate::__private::Pin<&'__pin mut ($field_ty)>
|
||||
};
|
||||
(@make_proj_field_mut;
|
||||
$field_ty:ty
|
||||
) => {
|
||||
($field_ty:ty) => {
|
||||
&'__pin mut ($field_ty)
|
||||
};
|
||||
(@make_proj_field_ref;
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_field_ref {
|
||||
(#[pin] $field_ty:ty) => {
|
||||
$crate::__private::Pin<&'__pin ($field_ty)>
|
||||
};
|
||||
(@make_proj_field_ref;
|
||||
$field_ty:ty
|
||||
) => {
|
||||
($field_ty:ty) => {
|
||||
&'__pin ($field_ty)
|
||||
};
|
||||
}
|
||||
|
||||
(@make_proj_field_replace;
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_make_proj_field_replace {
|
||||
(#[pin] $field_ty:ty) => {
|
||||
$crate::__private::PhantomData<$field_ty>
|
||||
};
|
||||
(@make_proj_field_replace;
|
||||
$field_ty:ty
|
||||
) => {
|
||||
($field_ty:ty) => {
|
||||
$field_ty
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================================================================
|
||||
// Parses attributes and determines visibility
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_internal {
|
||||
// parsing proj_mut_ident
|
||||
(
|
||||
[]
|
||||
@@ -1336,9 +1338,8 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
// parsing proj_ref_ident
|
||||
{
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
@@ -1346,7 +1347,7 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$proj_ref_ident]
|
||||
@@ -1355,9 +1356,8 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
// parsing proj_replace_ident
|
||||
{
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[]
|
||||
@@ -1365,7 +1365,7 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
@@ -1374,10 +1374,9 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
// this is actually part of a recursive step that picks off a single non-`pin_project_lite` attribute
|
||||
// there could be more to parse
|
||||
{
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
@@ -1385,7 +1384,7 @@ macro_rules! __pin_project_internal {
|
||||
|
||||
#[$($attr:tt)*]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
@@ -1394,18 +1393,17 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
// now determine visibility
|
||||
// if public, downgrade
|
||||
{
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
pub $struct_ty_ident:ident $ident:ident
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
$crate::__pin_project_internal! {
|
||||
) => {
|
||||
$crate::__pin_project_parse_generics! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
@@ -1414,15 +1412,15 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
{
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
$vis:vis $struct_ty_ident:ident $ident:ident
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
$crate::__pin_project_internal! {
|
||||
) => {
|
||||
$crate::__pin_project_parse_generics! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
@@ -1431,7 +1429,11 @@ macro_rules! __pin_project_internal {
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
// parse generics
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_parse_generics {
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
@@ -1459,7 +1461,7 @@ macro_rules! __pin_project_internal {
|
||||
}
|
||||
$(impl $($pinned_drop:tt)*)?
|
||||
) => {
|
||||
$crate::__pin_project_internal! { @expand;
|
||||
$crate::__pin_project_expand! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
@@ -1496,7 +1498,6 @@ macro_rules! __pin_project_internal {
|
||||
};
|
||||
}
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
use core::mem::ManuallyDrop;
|
||||
|
||||
Reference in New Issue
Block a user