Skip to content

Commit

Permalink
Fix trailing comma support in generics
Browse files Browse the repository at this point in the history
This reverts commit 950229c.
  • Loading branch information
taiki-e committed Sep 29, 2020
1 parent b82b312 commit 060656e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 26 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 trailing comma support in generics

## [0.1.8] - 2020-09-26

* Fix compatibility of generated code with `forbid(future_incompatible)`
Expand Down
67 changes: 41 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ macro_rules! __pin_project_internal {
),+
}

#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058
#[allow(clippy::used_underscore_binding)]
const _: () = {
Expand Down Expand Up @@ -460,7 +461,8 @@ macro_rules! __pin_project_internal {
(
$(#[$attrs:meta])*
pub struct $ident:ident $(<
$( $generics:tt
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
$( $generics:ident
$(: $generics_bound:path)?
$(: ?$generics_unsized_bound:path)?
$(: $generics_lifetime_bound:lifetime)?
Expand All @@ -484,18 +486,24 @@ macro_rules! __pin_project_internal {
$crate::__pin_project_internal! { @struct_internal;
[pub(crate)]
[$(#[$attrs])* pub struct $ident]
[$(< $( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
$(= $generics_default)?
),* >)?]
[$( $( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
),* )?]
[$( $( $generics ),* )?]
[$(<
$( $lifetime $(: $lifetime_bound)? ,)*
$( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
$(= $generics_default)?
),*
>)?]
[$(
$( $lifetime $(: $lifetime_bound)? ,)*
$( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
),*
)?]
[$( $( $lifetime ,)* $( $generics ),* )?]
[$(where $( $where_clause_ty
$(: $where_clause_bound)?
$(: ?$where_clause_unsized_bound)?
Expand All @@ -512,7 +520,8 @@ macro_rules! __pin_project_internal {
(
$(#[$attrs:meta])*
$vis:vis struct $ident:ident $(<
$( $generics:tt
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
$( $generics:ident
$(: $generics_bound:path)?
$(: ?$generics_unsized_bound:path)?
$(: $generics_lifetime_bound:lifetime)?
Expand All @@ -536,18 +545,24 @@ macro_rules! __pin_project_internal {
$crate::__pin_project_internal! { @struct_internal;
[$vis]
[$(#[$attrs])* $vis struct $ident]
[$(< $( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
$(= $generics_default)?
),* >)?]
[$( $( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
),* )?]
[$( $( $generics ),* )?]
[$(<
$( $lifetime $(: $lifetime_bound)? ,)*
$( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
$(= $generics_default)?
),*
>)?]
[$(
$( $lifetime $(: $lifetime_bound)? ,)*
$( $generics
$(: $generics_bound)?
$(: ?$generics_unsized_bound)?
$(: $generics_lifetime_bound)?
),*
)?]
[$( $( $lifetime ,)* $( $generics ),* )?]
[$(where $( $where_clause_ty
$(: $where_clause_bound)?
$(: ?$where_clause_unsized_bound)?
Expand Down
48 changes: 48 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,51 @@ fn no_infer_outlives() {
}
}
}

// https://github.com/taiki-e/pin-project-lite/issues/31
#[test]
fn trailing_comma() {
pub trait T {}

pin_project! {
pub struct S1<
A: T,
B: T,
> {
f: (A, B),
}
}

pin_project! {
pub struct S2<
A,
B,
>
where
A: T,
B: T,
{
f: (A, B),
}
}

pin_project! {
#[allow(explicit_outlives_requirements)]
pub struct S3<
'a,
A: 'a,
B: 'a,
> {
f: &'a (A, B),
}
}

// pin_project! {
// pub struct S4<
// 'a,
// 'b: 'a, // <-----
// > {
// f: &'a &'b (),
// }
// }
}

0 comments on commit 060656e

Please sign in to comment.