Skip to content

Commit

Permalink
Inline project methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 2, 2023
1 parent b379564 commit 182e128
Show file tree
Hide file tree
Showing 37 changed files with 81 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]

- Inline project methods.

## [1.1.1] - 2023-06-29

- Fix build error from dependency when built with `-Z minimal-versions`.
Expand Down
3 changes: 3 additions & 0 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ fn make_proj_impl(

let mut project = Some(quote! {
#allow_dead_code
#[inline]
#vis fn project<#lifetime>(
self: _pin_project::__private::Pin<&#lifetime mut Self>,
) -> #proj_ident #proj_ty_generics {
Expand All @@ -955,6 +956,7 @@ fn make_proj_impl(
let mut project_ref = Some(quote! {
#allow_dead_code
#[allow(clippy::missing_const_for_fn)]
#[inline]
#vis fn project_ref<#lifetime>(
self: _pin_project::__private::Pin<&#lifetime Self>,
) -> #proj_ref_ident #proj_ty_generics {
Expand All @@ -967,6 +969,7 @@ fn make_proj_impl(
// It is enough to only set the span of the signature.
let sig = quote_spanned! { span =>
#allow_dead_code
#[inline]
#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 @@ -67,6 +67,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> EnumProj<'pin, T, U> {
Expand All @@ -90,6 +91,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> EnumProjRef<'pin, T, U> {
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 @@ -42,6 +42,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -55,6 +56,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
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 @@ -36,6 +36,7 @@ const _: () = {
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -49,6 +50,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
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 @@ -118,6 +118,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> EnumProj<'pin, T, U> {
Expand Down Expand Up @@ -149,6 +150,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> EnumProjRef<'pin, T, U> {
Expand Down Expand Up @@ -179,6 +181,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -56,6 +56,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -72,6 +73,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
Expand All @@ -86,6 +88,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -47,6 +47,7 @@ const _: () = {
);
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -62,6 +63,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
Expand All @@ -76,6 +78,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -85,6 +85,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -105,6 +106,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
Expand All @@ -127,6 +129,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -47,6 +47,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[inline]
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 @@ -42,6 +42,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[inline]
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 @@ -45,6 +45,7 @@ const _: () = {
impl<T, U> Enum<T, U> {
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
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 @@ -77,6 +77,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -90,6 +91,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
Expand All @@ -102,6 +104,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -52,6 +52,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -65,6 +66,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
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 @@ -42,6 +42,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -55,6 +56,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
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 @@ -57,6 +57,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __StructProjection<'pin, T, U> {
Expand All @@ -70,6 +71,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __StructProjectionRef<'pin, T, U> {
Expand All @@ -82,6 +84,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -52,6 +52,7 @@ const _: () = {
}
impl<T, U> Struct<T, U> {
#[allow(dead_code)]
#[inline]
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)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
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 @@ -68,6 +68,7 @@ const _: () = {
extern crate pin_project as _pin_project;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -78,6 +79,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
Expand All @@ -87,6 +89,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -46,6 +46,7 @@ const _: () = {
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> Proj<'pin, T, U> {
Expand All @@ -56,6 +57,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
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 @@ -36,6 +36,7 @@ const _: () = {
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -49,6 +50,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
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 @@ -48,6 +48,7 @@ const _: () = {
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -61,6 +62,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> __TupleStructProjectionRef<'pin, T, U> {
Expand All @@ -73,6 +75,7 @@ const _: () = {
}
}
#[allow(dead_code)]
#[inline]
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 @@ -46,6 +46,7 @@ const _: () = {
TupleStruct<T, U>: 'pin;
impl<T, U> TupleStruct<T, U> {
#[allow(dead_code)]
#[inline]
fn project<'pin>(
self: _pin_project::__private::Pin<&'pin mut Self>,
) -> __TupleStructProjection<'pin, T, U> {
Expand All @@ -59,6 +60,7 @@ const _: () = {
}
#[allow(dead_code)]
#[allow(clippy::missing_const_for_fn)]
#[inline]
fn project_ref<'pin>(
self: _pin_project::__private::Pin<&'pin Self>,
) -> ProjRef<'pin, T, U> {
Expand Down
Loading

0 comments on commit 182e128

Please sign in to comment.