Skip to content

Commit

Permalink
Fix warnings when #[pin_project] used within macro_rules! macros
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 15, 2020
1 parent c98d3bd commit 93a1d49
Show file tree
Hide file tree
Showing 39 changed files with 670 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

* Fix warnings when `#[pin_project]` attribute used within `macro_rules!` macros.

## [1.0.0] - 2020-10-13

* [Remove deprecated `#[project]`, `#[project_ref]`, and `#[project_replace]` attributes.](https://github.com/taiki-e/pin-project/pull/265)
Expand Down
16 changes: 12 additions & 4 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,22 @@ fn global_allowed_lints() -> TokenStream {
#[allow(box_pointers)] // This lint warns use of the `Box` type.
#[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993
#[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058
#[allow(unreachable_pub)] // This lint warns `pub` field in private struct.
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
}
}

/// Returns attributes used on projected types.
fn proj_allowed_lints(kind: TypeKind) -> (TokenStream, TokenStream, TokenStream) {
let large_enum_variant =
if kind == Enum { Some(quote!(#[allow(clippy::large_enum_variant)])) } else { None };
let large_enum_variant = if kind == Enum {
Some(quote! {
#[allow(variant_size_differences)]
#[allow(clippy::large_enum_variant)]
})
} else {
None
};
let global_allowed_lints = global_allowed_lints();
let proj_mut = quote! {
#[allow(dead_code)] // This lint warns unused fields/variants.
Expand All @@ -123,7 +130,6 @@ fn proj_allowed_lints(kind: TypeKind) -> (TokenStream, TokenStream, TokenStream)
};
let proj_own = quote! {
#[allow(dead_code)] // This lint warns unused fields/variants.
#[allow(unreachable_pub)] // This lint warns `pub` field in private struct.
#large_enum_variant
#global_allowed_lints
};
Expand Down Expand Up @@ -788,6 +794,7 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
// `__UnpinStruct` type must also be public.
// However, we ensure that the user can never actually reference
// this 'public' type by creating this type in the inside of `const`.
#[allow(missing_debug_implementations)]
#vis struct #struct_ident #proj_generics #where_clause {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
#lifetime, (#(::pin_project::__private::PhantomData<#type_params>),*)
Expand Down Expand Up @@ -934,6 +941,7 @@ fn make_proj_impl(
}
});
let mut project_ref = Some(quote! {
#[allow(clippy::missing_const_for_fn)]
#vis fn project_ref<#lifetime>(
self: ::pin_project::__private::Pin<&#lifetime Self>,
) -> #proj_ref_ident #proj_ty_generics {
Expand Down
5 changes: 5 additions & 0 deletions tests/expand/tests/expand/default-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Enum<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum EnumProj<'pin, T, U>
Expand All @@ -33,6 +34,7 @@ where
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum EnumProjRef<'pin, T, U>
Expand All @@ -49,6 +51,7 @@ where
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -70,6 +73,7 @@ const _: () = {
}
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> EnumProjRef<'pin, T, U> {
Expand All @@ -87,6 +91,7 @@ const _: () = {
}
}
}
#[allow(missing_debug_implementations)]
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
5 changes: 5 additions & 0 deletions tests/expand/tests/expand/default-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct Struct<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -18,6 +19,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __StructProjection<'pin, T, U>
Expand All @@ -32,6 +34,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __StructProjectionRef<'pin, T, U>
Expand All @@ -53,6 +56,7 @@ const _: () = {
}
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
Expand All @@ -70,6 +74,7 @@ const _: () = {
let _ = &this.pinned;
let _ = &this.unpinned;
}
#[allow(missing_debug_implementations)]
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
5 changes: 5 additions & 0 deletions tests/expand/tests/expand/default-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct TupleStruct<T, U>(#[pin] T, U);
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -14,6 +15,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __TupleStructProjection<'pin, T, U>(
Expand All @@ -27,6 +29,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __TupleStructProjectionRef<'pin, T, U>(
Expand All @@ -44,6 +47,7 @@ const _: () = {
__TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1)
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
Expand All @@ -58,6 +62,7 @@ const _: () = {
let _ = &this.0;
let _ = &this.1;
}
#[allow(missing_debug_implementations)]
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
7 changes: 6 additions & 1 deletion tests/expand/tests/expand/multifields-enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum Enum<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum EnumProj<'pin, T, U>
Expand All @@ -43,6 +44,7 @@ where
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum EnumProjRef<'pin, T, U>
Expand All @@ -64,11 +66,11 @@ where
Unit,
}
#[allow(dead_code)]
#[allow(unreachable_pub)]
#[allow(clippy::large_enum_variant)]
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum EnumProjOwn<T, U> {
Expand All @@ -89,6 +91,7 @@ enum EnumProjOwn<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand Down Expand Up @@ -120,6 +123,7 @@ const _: () = {
}
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> EnumProjRef<'pin, T, U> {
Expand Down Expand Up @@ -205,6 +209,7 @@ const _: () = {
}
}
}
#[allow(missing_debug_implementations)]
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
7 changes: 6 additions & 1 deletion tests/expand/tests/expand/multifields-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Struct<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -21,6 +22,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __StructProjection<'pin, T, U>
Expand All @@ -37,6 +39,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __StructProjectionRef<'pin, T, U>
Expand All @@ -49,10 +52,10 @@ const _: () = {
unpinned2: &'pin (U),
}
#[allow(dead_code)]
#[allow(unreachable_pub)]
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __StructProjectionOwned<T, U> {
Expand Down Expand Up @@ -80,6 +83,7 @@ const _: () = {
}
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
Expand Down Expand Up @@ -135,6 +139,7 @@ const _: () = {
let _ = &this.unpinned1;
let _ = &this.unpinned2;
}
#[allow(missing_debug_implementations)]
struct __Struct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct TupleStruct<T, U>(#[pin] T, #[pin] T, U, U);
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -14,6 +15,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __TupleStructProjection<'pin, T, U>(
Expand All @@ -29,6 +31,7 @@ const _: () = {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __TupleStructProjectionRef<'pin, T, U>(
Expand All @@ -40,10 +43,10 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
#[allow(dead_code)]
#[allow(unreachable_pub)]
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
struct __TupleStructProjectionOwned<T, U>(
Expand All @@ -66,6 +69,7 @@ const _: () = {
)
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
Expand Down Expand Up @@ -111,6 +115,7 @@ const _: () = {
let _ = &this.2;
let _ = &this.3;
}
#[allow(missing_debug_implementations)]
struct __TupleStruct<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
7 changes: 6 additions & 1 deletion tests/expand/tests/expand/naming-enum-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Enum<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum Proj<'pin, T, U>
Expand All @@ -33,6 +34,7 @@ where
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum ProjRef<'pin, T, U>
Expand All @@ -47,11 +49,11 @@ where
Unit,
}
#[allow(dead_code)]
#[allow(unreachable_pub)]
#[allow(clippy::large_enum_variant)]
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
enum ProjOwn<T, U> {
Expand All @@ -65,6 +67,7 @@ enum ProjOwn<T, U> {
#[allow(box_pointers)]
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(unreachable_pub)]
#[allow(clippy::pattern_type_mismatch)]
#[allow(clippy::redundant_pub_crate)]
#[allow(clippy::used_underscore_binding)]
Expand All @@ -84,6 +87,7 @@ const _: () = {
}
}
}
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: ::pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
Expand Down Expand Up @@ -148,6 +152,7 @@ const _: () = {
}
}
}
#[allow(missing_debug_implementations)]
struct __Enum<'pin, T, U> {
__pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<
'pin,
Expand Down
Loading

0 comments on commit 93a1d49

Please sign in to comment.