Skip to content

Commit

Permalink
Force proj_vis to pub(crate) if visibility cannot be parsed due to ru…
Browse files Browse the repository at this point in the history
…stc bug
  • Loading branch information
taiki-e committed Aug 9, 2023
1 parent 220ea32 commit 46229f1
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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! {
Expand All @@ -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)*
}
};
Expand All @@ -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)*
}
};
Expand All @@ -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
Expand Down

0 comments on commit 46229f1

Please sign in to comment.