Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force proj_vis to pub(crate) if visibility cannot be parsed due to rustc bug #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 48 additions & 13 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 @@ -805,7 +806,6 @@ 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.
Expand Down Expand Up @@ -899,7 +899,6 @@ 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)
Expand Down Expand Up @@ -978,7 +977,6 @@ 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>,
Expand Down Expand Up @@ -1013,7 +1011,6 @@ 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>,
Expand Down Expand Up @@ -1062,7 +1059,6 @@ 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>,
Expand Down Expand Up @@ -1107,7 +1103,6 @@ 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>,
Expand Down Expand Up @@ -1503,7 +1498,9 @@ 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)?]
Expand All @@ -1519,7 +1516,45 @@ macro_rules! __pin_project_internal {
[$($proj_replace_ident)?]
[$($proj_not_unpin_mark)?]
[$($attrs)*]
[pub $struct_ty_ident $ident pub(crate)]
[pub, pub(crate), $struct_ty_ident $ident]
$($tt)*
}
};
(
[$($proj_mut_ident:ident)?]
[$($proj_ref_ident:ident)?]
[$($proj_replace_ident:ident)?]
[$( ! $proj_not_unpin_mark:ident)?]
[$($attrs:tt)*]
pub($($vis_path: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)*]
[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 @@ -1538,7 +1573,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 @@ -1553,7 +1588,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_vis:vis]
[$vis:vis, $proj_vis:vis, $struct_ty_ident:ident $ident:ident]
$(<
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
$( $generics:ident
Expand Down
6 changes: 0 additions & 6 deletions tests/expand/default/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ enum Enum<T, U> {
Struct { pinned: T, unpinned: U },
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -21,7 +20,6 @@ where
},
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -39,7 +37,6 @@ where
},
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::mut_mut)]
Expand All @@ -54,7 +51,6 @@ enum EnumProjReplace<T, U> {
#[allow(clippy::used_underscore_binding)]
const _: () = {
impl<T, U> Enum<T, U> {
#[doc(hidden)]
#[inline]
fn project<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
Expand All @@ -73,7 +69,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_ref<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
Expand All @@ -92,7 +87,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_replace(
self: ::pin_project_lite::__private::Pin<&mut Self>,
Expand Down
4 changes: 0 additions & 4 deletions tests/expand/default/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct Struct<T, U> {
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
const _: () = {
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -24,7 +23,6 @@ const _: () = {
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
unpinned: &'__pin mut (U),
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -40,7 +38,6 @@ const _: () = {
unpinned: &'__pin (U),
}
impl<T, U> Struct<T, U> {
#[doc(hidden)]
#[inline]
fn project<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
Expand All @@ -53,7 +50,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_ref<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
Expand Down
2 changes: 0 additions & 2 deletions tests/expand/multifields/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ enum Enum<T, U> {
Struct { pinned1: T, pinned2: T, unpinned1: U, unpinned2: U },
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::mut_mut)]
Expand All @@ -23,7 +22,6 @@ enum EnumProjReplace<T, U> {
#[allow(clippy::used_underscore_binding)]
const _: () = {
impl<T, U> Enum<T, U> {
#[doc(hidden)]
#[inline]
fn project_replace(
self: ::pin_project_lite::__private::Pin<&mut Self>,
Expand Down
6 changes: 0 additions & 6 deletions tests/expand/multifields/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ struct Struct<T, U> {
unpinned1: U,
unpinned2: U,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::mut_mut)]
Expand All @@ -23,7 +22,6 @@ struct StructProjReplace<T, U> {
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
const _: () = {
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -40,7 +38,6 @@ const _: () = {
unpinned1: &'__pin mut (U),
unpinned2: &'__pin mut (U),
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -58,7 +55,6 @@ const _: () = {
unpinned2: &'__pin (U),
}
impl<T, U> Struct<T, U> {
#[doc(hidden)]
#[inline]
fn project<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
Expand All @@ -74,7 +70,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_ref<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
Expand All @@ -89,7 +84,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_replace(
self: ::pin_project_lite::__private::Pin<&mut Self>,
Expand Down
6 changes: 0 additions & 6 deletions tests/expand/naming/enum-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ enum Enum<T, U> {
Struct { pinned: T, unpinned: U },
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -21,7 +20,6 @@ where
},
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -39,7 +37,6 @@ where
},
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::mut_mut)]
Expand All @@ -54,7 +51,6 @@ enum EnumProjReplace<T, U> {
#[allow(clippy::used_underscore_binding)]
const _: () = {
impl<T, U> Enum<T, U> {
#[doc(hidden)]
#[inline]
fn project<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
Expand All @@ -73,7 +69,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_ref<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
Expand All @@ -92,7 +87,6 @@ const _: () = {
}
}
}
#[doc(hidden)]
#[inline]
fn project_replace(
self: ::pin_project_lite::__private::Pin<&mut Self>,
Expand Down
2 changes: 0 additions & 2 deletions tests/expand/naming/enum-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ enum Enum<T, U> {
Struct { pinned: T, unpinned: U },
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -26,7 +25,6 @@ where
#[allow(clippy::used_underscore_binding)]
const _: () = {
impl<T, U> Enum<T, U> {
#[doc(hidden)]
#[inline]
fn project<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
Expand Down
2 changes: 0 additions & 2 deletions tests/expand/naming/enum-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ enum Enum<T, U> {
Struct { pinned: T, unpinned: U },
Unit,
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(single_use_lifetimes)]
#[allow(clippy::unknown_clippy_lints)]
Expand All @@ -26,7 +25,6 @@ where
#[allow(clippy::used_underscore_binding)]
const _: () = {
impl<T, U> Enum<T, U> {
#[doc(hidden)]
#[inline]
fn project_ref<'__pin>(
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
Expand Down
Loading