Skip to content

Commit

Permalink
Suppress dead_code lint in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 2, 2022
1 parent 836eb25 commit 9ce302b
Show file tree
Hide file tree
Showing 37 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- [Suppress `dead_code` lint in generated code.](https://github.com/taiki-e/pin-project/pull/346)

## [1.0.10] - 2021-12-31

- Revert the increase of the minimal version of `syn` that was done in 1.0.9.
Expand Down
8 changes: 8 additions & 0 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,14 @@ fn make_proj_impl(
let orig_ty_generics = cx.orig.generics.split_for_impl().1;
let proj_ty_generics = cx.proj.generics.split_for_impl().1;
let (impl_generics, ty_generics, where_clause) = cx.orig.generics.split_for_impl();
// TODO: For enums and project_replace, dead_code warnings should not be
// allowed because methods are not generated unless explicitly specified.
// However, there is currently no good way to allow warnings for generated
// code, so we allow warnings for all methods for now.
let allow_dead_code = quote! { #[allow(dead_code)] };

let mut project = Some(quote! {
#allow_dead_code
#vis fn project<#lifetime>(
self: _pin_project::__private::Pin<&#lifetime mut Self>,
) -> #proj_ident #proj_ty_generics {
Expand All @@ -944,6 +950,7 @@ fn make_proj_impl(
}
});
let mut project_ref = Some(quote! {
#allow_dead_code
#[allow(clippy::missing_const_for_fn)]
#vis fn project_ref<#lifetime>(
self: _pin_project::__private::Pin<&#lifetime Self>,
Expand All @@ -956,6 +963,7 @@ fn make_proj_impl(
let mut project_replace = cx.project_replace.span().map(|span| {
// It is enough to only set the span of the signature.
let sig = quote_spanned! { span =>
#allow_dead_code
#vis fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/default/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> EnumProj<'pin, T, U> {
Expand All @@ -84,6 +85,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/default/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const _: () = {
unpinned: &'pin (U),
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -51,6 +52,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/default/tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -45,6 +46,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/multifields/enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> EnumProj<'pin, T, U> {
Expand Down Expand Up @@ -142,6 +143,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down Expand Up @@ -172,6 +174,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/multifields/struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const _: () = {
unpinned2: U,
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -68,6 +69,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -82,6 +84,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/multifields/tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const _: () = {
U,
);
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -58,6 +59,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -72,6 +74,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/naming/enum-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -98,6 +99,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -120,6 +122,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
1 change: 1 addition & 0 deletions tests/expand/naming/enum-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand Down
1 change: 1 addition & 0 deletions tests/expand/naming/enum-own.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
1 change: 1 addition & 0 deletions tests/expand/naming/enum-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/naming/struct-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -83,6 +84,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -95,6 +97,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/struct-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const _: () = {
unpinned: &'pin (U),
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -60,6 +61,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/struct-none.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const _: () = {
unpinned: &'pin (U),
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -51,6 +52,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/naming/struct-own.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const _: () = {
unpinned: &'pin (U),
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -65,6 +66,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -77,6 +79,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/struct-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const _: () = {
unpinned: &'pin mut (U),
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -60,6 +61,7 @@ const _: () = {
}
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/naming/tuple_struct-all.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const _: () = {
#[allow(unused_extern_crates)]
extern crate pin_project as _pin_project;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -71,6 +72,7 @@ const _: () = {
Proj(_pin_project::__private::Pin::new_unchecked(_0), _1)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -80,6 +82,7 @@ const _: () = {
ProjRef(_pin_project::__private::Pin::new_unchecked(_0), _1)
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/tuple_struct-mut.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -51,6 +52,7 @@ const _: () = {
Proj(_pin_project::__private::Pin::new_unchecked(_0), _1)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/tuple_struct-none.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -45,6 +46,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down
3 changes: 3 additions & 0 deletions tests/expand/naming/tuple_struct-own.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -56,6 +57,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand All @@ -68,6 +70,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
fn project_replace(
self: _pin_project::__private::Pin<&mut Self>,
__replacement: Self,
Expand Down
2 changes: 2 additions & 0 deletions tests/expand/naming/tuple_struct-ref.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const _: () = {
where
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -54,6 +55,7 @@ const _: () = {
)
}
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
Expand Down

0 comments on commit 9ce302b

Please sign in to comment.