From 46229f1b5708d71add70e34b349c948f760fa6e2 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 9 Aug 2023 22:51:15 +0900 Subject: [PATCH] Force proj_vis to pub(crate) if visibility cannot be parsed due to rustc bug --- src/lib.rs | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3da246e..594970a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,9 +203,10 @@ pin-project supports this. /// ``` /// /// The visibility of the projected types and projection methods is based on the -/// original type. However, if the visibility of the original type is `pub`, the -/// visibility of the projected types and the projection methods is downgraded -/// to `pub(crate)`. +/// original type. However, if the visibility of the original type is `pub` or the +/// visibility that has been parsed once by caller macro and can no longer be re-parsed by +/// us (due to [rustc bug](https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1666940521)), +/// the visibility of the projected types and the projection methods is forced to `pub(crate)`. /// /// # Safety /// @@ -1497,14 +1498,16 @@ macro_rules! __pin_project_internal { } }; // now determine visibility - // if public, downgrade + // `pub` or the visibility that has been parsed once by caller macro and + // can no longer be re-parsed by us (due to rustc bug), is forced to `pub(crate)`. + // https://github.com/taiki-e/pin-project-lite/issues/77#issuecomment-1666940521 ( [$($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 + pub($($vis_path:tt)*) $struct_ty_ident:ident $ident:ident $($tt:tt)* ) => { $crate::__pin_project_parse_generics! { @@ -1513,7 +1516,26 @@ macro_rules! __pin_project_internal { [$($proj_replace_ident)?] [$($proj_not_unpin_mark)?] [$($attrs)*] - [pub $struct_ty_ident $ident pub(crate)] + [pub($($vis_path)*), pub($($vis_path)*), $struct_ty_ident $ident] + $($tt)* + } + }; + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$( ! $proj_not_unpin_mark:ident)?] + [$($attrs:tt)*] + $struct_ty_ident:ident $ident:ident + $($tt:tt)* + ) => { + $crate::__pin_project_parse_generics! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$($proj_not_unpin_mark)?] + [$($attrs)*] + [,,$struct_ty_ident $ident] $($tt)* } }; @@ -1532,7 +1554,7 @@ macro_rules! __pin_project_internal { [$($proj_replace_ident)?] [$($proj_not_unpin_mark)?] [$($attrs)*] - [$vis $struct_ty_ident $ident $vis] + [$vis, pub(crate), $struct_ty_ident $ident] $($tt)* } }; @@ -1547,7 +1569,7 @@ macro_rules! __pin_project_parse_generics { [$($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, $proj_ty_vis:vis, $struct_ty_ident:ident $ident:ident] $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? $( $generics:ident