Skip to content

Commit

Permalink
Reorder rules in __pin_project_internal!.
Browse files Browse the repository at this point in the history
This isn't useful by itself, but it sets things up for the next commit,
which will break `__pin_project_internal!` into a number of smaller
macros.
  • Loading branch information
nnethercote committed Apr 19, 2022
1 parent 5fe3257 commit 0e13089
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,25 +310,6 @@ macro_rules! pin_project {
#[doc(hidden)]
#[macro_export]
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)*
) => {};
// ignores make_proj_replace_ty without a projection identity
(@make_proj_replace_ty;
[] // no identity given, so we ignore the projection
$($field:tt)*
) => {};
(@$struct_ty_ident:ident=>make_proj_method;
[]
$($variant:tt)*
) => {};
(@$struct_ty_ident:ident=>make_proj_replace_method;
[]
$($field:tt)*
) => {};
// =============================================================================================
// struct:main
(@expand;
Expand Down Expand Up @@ -690,49 +671,12 @@ macro_rules! __pin_project_internal {
),+
}
};
// construct a projected type
// macro helpers
// ignores any projection without a projection identity
(@make_proj_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis $struct_ty_ident:ident $ident:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
[$($body_data:tt)+]
) => {
#[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.
// We allow this lint for compatibility with older compilers.
#[allow(clippy::unknown_clippy_lints)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project)
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
#[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref)
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
$proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*>
where
$ident <$($ty_generics)*>: '__pin
$(, $($where_clause)*)?
{
$($body_data)+
}
};
// construct a project_replace type
(@make_proj_replace_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis $struct_ty_ident:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
[$($body_data:tt)+]
) => {
#[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)
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
$proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*>
where
$($($where_clause)*)?
{
$($body_data)+
}
};
[] // 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
Expand Down Expand Up @@ -766,31 +710,6 @@ macro_rules! __pin_project_internal {
]
}
};
(@make_proj_replace_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis struct]
[$make_proj_field:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
{
$(
$(#[$pin:ident])?
$field_vis:vis $field:ident: $field_ty:ty
),+ $(,)?
}
) => {
$crate::__pin_project_internal!{@make_proj_replace_ty;
[$proj_ty_ident]
[$proj_vis struct]
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
[
$(
$field_vis $field: $crate::__pin_project_internal!(@$make_proj_field;
$(#[$pin])? $field_ty
)
),+
]
}
};
// =============================================================================================
// enum:make_proj_ty
(@make_proj_ty;
Expand Down Expand Up @@ -827,6 +746,60 @@ macro_rules! __pin_project_internal {
]
}
};
// construct a projected type
(@make_proj_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis $struct_ty_ident:ident $ident:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
[$($body_data:tt)+]
) => {
#[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.
// We allow this lint for compatibility with older compilers.
#[allow(clippy::unknown_clippy_lints)]
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project)
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
#[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref)
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
$proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*>
where
$ident <$($ty_generics)*>: '__pin
$(, $($where_clause)*)?
{
$($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;
[$proj_ty_ident:ident]
[$proj_vis:vis struct]
[$make_proj_field:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
{
$(
$(#[$pin:ident])?
$field_vis:vis $field:ident: $field_ty:ty
),+ $(,)?
}
) => {
$crate::__pin_project_internal!{@make_proj_replace_ty;
[$proj_ty_ident]
[$proj_vis struct]
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?]
[
$(
$field_vis $field: $crate::__pin_project_internal!(@$make_proj_field;
$(#[$pin])? $field_ty
)
),+
]
}
};
(@make_proj_replace_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis enum]
Expand Down Expand Up @@ -861,6 +834,25 @@ macro_rules! __pin_project_internal {
]
}
};
// construct a project_replace type
(@make_proj_replace_ty;
[$proj_ty_ident:ident]
[$proj_vis:vis $struct_ty_ident:ident]
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
[$($body_data:tt)+]
) => {
#[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)
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
$proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*>
where
$($($where_clause)*)?
{
$($body_data)+
}
};
// =============================================================================================
(@make_proj_replace_block;
[$($proj_path: tt)+]
Expand Down Expand Up @@ -898,6 +890,10 @@ macro_rules! __pin_project_internal {
// =============================================================================================
// 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;
[$proj_ty_ident:ident $_ignored_default_arg:ident]
[$proj_vis:vis]
Expand Down Expand Up @@ -941,6 +937,10 @@ macro_rules! __pin_project_internal {
}
};

(@$struct_ty_ident:ident=>make_proj_replace_method;
[]
$($field:tt)*
) => {};
(@struct=>make_proj_replace_method;
[$proj_ty_ident:ident]
[$proj_vis:vis]
Expand Down

0 comments on commit 0e13089

Please sign in to comment.