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

Fix trailing comma support in generics #32

Merged
merged 1 commit into from
Sep 29, 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
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
1 change: 1 addition & 0 deletions tests/expand/tests/expand/default-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ struct Struct<T, U> {
pinned: T,
unpinned: U,
}
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const _: () = {
Expand Down
1 change: 1 addition & 0 deletions tests/expand/tests/expand/pub-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub struct Struct<T, U> {
pub pinned: T,
pub unpinned: U,
}
#[allow(explicit_outlives_requirements)]
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const _: () = {
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 (),
// }
// }
Comment on lines +427 to +434
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't seem to compile even in previous versions.

}