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

Hide generated items from --document-private-items #211

Merged
merged 1 commit into from
May 7, 2020
Merged
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
1 change: 1 addition & 0 deletions examples/enum-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ where
Unpinned(&'pin (U)),
}

#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Enum: () = {
impl<T, U> Enum<T, U> {
Expand Down
1 change: 1 addition & 0 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ where
field: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
}

#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<'a, T> Struct<'a, T> {
Expand Down
1 change: 1 addition & 0 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ where
unpinned: &'pin (U),
}

#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
Expand Down
5 changes: 3 additions & 2 deletions examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where
unpinned: &'pin (U),
}

#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
Expand Down Expand Up @@ -72,8 +73,6 @@ const __SCOPE_Struct: () = {
}
}

unsafe impl<T: Unpin, U> UnsafeUnpin for Struct<T, U> {}

#[allow(single_use_lifetimes)]
impl<'pin, T, U> ::pin_project::__reexport::marker::Unpin for Struct<T, U> where
::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin
Expand Down Expand Up @@ -105,4 +104,6 @@ const __SCOPE_Struct: () = {
}
};

unsafe impl<T: Unpin, U> UnsafeUnpin for Struct<T, U> {}

fn main() {}
10 changes: 8 additions & 2 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub(super) fn parse_derive(input: TokenStream) -> Result<TokenStream> {
// * https://github.com/rust-lang/rust/issues/63281
// * https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867
// * https://github.com/taiki-e/pin-project/pull/70
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const #dummy_const: () = {
#proj_impl
Expand All @@ -66,6 +67,7 @@ pub(super) fn parse_derive(input: TokenStream) -> Result<TokenStream> {

let dummy_const = format_ident!("__SCOPE_{}", ident);
proj_items.extend(quote! {
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const #dummy_const: () = {
#proj_impl
Expand Down Expand Up @@ -379,16 +381,18 @@ impl<'a> Context<'a> {
};

let mut proj_items = quote! {
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis struct #proj_ident #proj_generics #where_clause_fields
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis struct #proj_ref_ident #proj_generics #where_clause_ref_fields
};

if self.replace.is_some() {
// Currently, using quote_spanned here does not seem to have any effect on the diagnostics.
proj_items.extend(quote! {
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis struct #proj_own_ident #orig_generics #where_clause_own_fields
});
Expand Down Expand Up @@ -451,20 +455,22 @@ impl<'a> Context<'a> {
let where_clause = &self.proj.where_clause;

let mut proj_items = quote! {
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis enum #proj_ident #proj_generics #where_clause {
#proj_variants
}
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis enum #proj_ref_ident #proj_generics #where_clause {
#proj_ref_variants
}
};

if self.replace.is_some() {
// Currently, using quote_spanned here does not seem to have any effect on the diagnostics.
proj_items.extend(quote! {
#[doc(hidden)] // TODO: If the user gave it a name, it should appear in the document.
#[allow(dead_code)] // This lint warns unused fields/variants.
#vis enum #proj_own_ident #orig_generics #orig_where_clause {
#proj_own_variants
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/tests/enum/default.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum Enum<T, U> {
Pinned(#[pin] T),
Unpinned(U),
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
enum __EnumProjection<'pin, T, U>
Expand All @@ -13,6 +14,7 @@ where
Pinned(::pin_project::__reexport::pin::Pin<&'pin mut (T)>),
Unpinned(&'pin mut (U)),
}
#[doc(hidden)]
#[allow(dead_code)]
enum __EnumProjectionRef<'pin, T, U>
where
Expand All @@ -21,6 +23,7 @@ where
Pinned(::pin_project::__reexport::pin::Pin<&'pin (T)>),
Unpinned(&'pin (U)),
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Enum: () = {
impl<T, U> Enum<T, U> {
Expand Down
4 changes: 4 additions & 0 deletions tests/expand/tests/enum/project_replace.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Enum<T, U> {
},
None,
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
enum __EnumProjection<'pin, T, U>
Expand All @@ -20,6 +21,7 @@ where
},
None,
}
#[doc(hidden)]
#[allow(dead_code)]
enum __EnumProjectionRef<'pin, T, U>
where
Expand All @@ -31,6 +33,7 @@ where
},
None,
}
#[doc(hidden)]
#[allow(dead_code)]
enum __EnumProjectionOwned<T, U> {
V {
Expand All @@ -39,6 +42,7 @@ enum __EnumProjectionOwned<T, U> {
},
None,
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Enum: () = {
impl<T, U> Enum<T, U> {
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/tests/struct/default.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct Struct<T, U> {
pinned: T,
unpinned: U,
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
struct __StructProjection<'pin, T, U>
Expand All @@ -14,6 +15,7 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
unpinned: &'pin mut (U),
}
#[doc(hidden)]
#[allow(dead_code)]
struct __StructProjectionRef<'pin, T, U>
where
Expand All @@ -22,6 +24,7 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
unpinned: &'pin (U),
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/tests/struct/pinned_drop.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Struct<'a, T> {
#[pin]
field: T,
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
pub(crate) struct __StructProjection<'pin, 'a, T>
Expand All @@ -15,6 +16,7 @@ where
was_dropped: &'pin mut (&'a mut bool),
field: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
}
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) struct __StructProjectionRef<'pin, 'a, T>
where
Expand All @@ -23,6 +25,7 @@ where
was_dropped: &'pin (&'a mut bool),
field: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<'a, T> Struct<'a, T> {
Expand Down
4 changes: 4 additions & 0 deletions tests/expand/tests/struct/project_replace.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct Struct<T, U> {
pinned: T,
unpinned: U,
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
struct __StructProjection<'pin, T, U>
Expand All @@ -14,6 +15,7 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
unpinned: &'pin mut (U),
}
#[doc(hidden)]
#[allow(dead_code)]
struct __StructProjectionRef<'pin, T, U>
where
Expand All @@ -22,11 +24,13 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
unpinned: &'pin (U),
}
#[doc(hidden)]
#[allow(dead_code)]
struct __StructProjectionOwned<T, U> {
pinned: ::pin_project::__reexport::marker::PhantomData<T>,
unpinned: U,
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/tests/struct/unsafe_unpin.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct Struct<T, U> {
pinned: T,
unpinned: U,
}
#[doc(hidden)]
#[allow(clippy::mut_mut)]
#[allow(dead_code)]
pub(crate) struct __StructProjection<'pin, T, U>
Expand All @@ -14,6 +15,7 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin mut (T)>,
unpinned: &'pin mut (U),
}
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) struct __StructProjectionRef<'pin, T, U>
where
Expand All @@ -22,6 +24,7 @@ where
pinned: ::pin_project::__reexport::pin::Pin<&'pin (T)>,
unpinned: &'pin (U),
}
#[doc(hidden)]
#[allow(non_upper_case_globals)]
const __SCOPE_Struct: () = {
impl<T, U> Struct<T, U> {
Expand Down