diff --git a/src/lib.rs b/src/lib.rs index 962ac8e..d74ddf2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,7 +149,7 @@ macro_rules! pin_project { pub struct $ident:ident $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? - $( $generics:ident $(: $generics_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)? + $( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)? >)? $(where $($where_clause_ty:ty : $where_clause_bound:path),* $(,)? @@ -166,7 +166,7 @@ macro_rules! pin_project { pub struct $ident $(< $( $lifetime $(: $lifetime_bound)? ),* - $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),* + $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),* >)? $(where $($where_clause_ty : $where_clause_bound),* @@ -184,7 +184,7 @@ macro_rules! pin_project { $vis:vis struct $ident:ident $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? - $( $generics:ident $(: $generics_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)? + $( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)? >)? $(where $($where_clause_ty:ty : $where_clause_bound:path),* $(,)? @@ -201,7 +201,7 @@ macro_rules! pin_project { $vis struct $ident $(< $( $lifetime $(: $lifetime_bound)? ),* - $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),* + $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),* >)? $(where $($where_clause_ty : $where_clause_bound),* @@ -223,7 +223,7 @@ macro_rules! pin_project { $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* // limitation: does not support multiple trait/lifetime bounds and ? trait bounds. - $( $generics:ident $(: $generics_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* + $( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* >)? $(where // limitation: does not support multiple trait/lifetime bounds and ? trait bounds. @@ -239,7 +239,7 @@ macro_rules! pin_project { ) => { $(#[$attrs])* $vis struct $ident - $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ,)* >)? + $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ,)* >)? $(where $($where_clause_ty: $where_clause_bound),* )* @@ -254,7 +254,7 @@ macro_rules! pin_project { #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. $proj_vis struct Projection - <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* )?> + <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?> $(where $($where_clause_ty: $where_clause_bound),* )* @@ -265,7 +265,7 @@ macro_rules! pin_project { } #[allow(dead_code)] // This lint warns unused fields/variants. $proj_vis struct ProjectionRef - <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* )?> + <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?> $(where $($where_clause_ty: $where_clause_bound),* )* @@ -275,7 +275,7 @@ macro_rules! pin_project { ),+ } - impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* >)? + impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* >)? $ident $(< $($lifetime,)* $($generics),* >)? $(where $($where_clause_ty: $where_clause_bound),* @@ -333,7 +333,7 @@ macro_rules! pin_project { // // See also https://github.com/taiki-e/pin-project/pull/53. $vis struct __Origin - <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* )?> + <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?> $(where $($where_clause_ty: $where_clause_bound),* )* @@ -343,7 +343,7 @@ macro_rules! pin_project { $field: $crate::pin_project!(@make_unpin_bound $(#[$pin])? $field_ty) ),+ } - impl <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* )?> ::core::marker::Unpin + impl <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?> ::core::marker::Unpin for $ident $(< $($lifetime,)* $($generics),* >)? where __Origin <'__pin $(, $($lifetime,)* $($generics),* )?>: ::core::marker::Unpin @@ -366,7 +366,7 @@ macro_rules! pin_project { #[allow(clippy::drop_bounds)] impl MustNotImplDrop for T {} #[allow(single_use_lifetimes)] - impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),*>)? MustNotImplDrop + impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),*>)? MustNotImplDrop for $ident $(< $($lifetime,)* $($generics),* >)? $(where $($where_clause_ty: $where_clause_bound),* @@ -390,7 +390,7 @@ macro_rules! pin_project { #[allow(non_snake_case)] #[deny(safe_packed_borrows)] fn __assert_not_repr_packed - $(< $($lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: $generics_lifetime_bound)? ),* >)? + $(< $($lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* >)? ( this: &$ident $(< $($lifetime,)* $($generics),* >)? ) diff --git a/tests/test.rs b/tests/test.rs index 5a5846e..9077149 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -80,6 +80,20 @@ fn where_clause_and_associated_type_fields() { // impl Static for Struct3 {} } +// #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 +// #[test] +// fn unsized_in_where_clause() { +// pin_project! { +// struct Struct +// where +// I: ?Sized, +// { +// #[pin] +// field: I, +// } +// } +// } + #[test] fn derive_copy() { pin_project! { @@ -110,11 +124,11 @@ fn move_out() { #[test] fn trait_bounds_on_type_generics() { - // pin_project! { - // pub struct Struct1<'a, T: ?Sized> { - // field: &'a mut T, - // } - // } + pin_project! { + pub struct Struct1<'a, T: ?Sized> { + field: &'a mut T, + } + } pin_project! { pub struct Struct2<'a, T: ::core::fmt::Debug> { @@ -282,21 +296,23 @@ fn trivial_bounds() { } } -// #[test] -// fn dst() { -// pin_project! { -// pub struct A { -// x: T, -// } -// } +#[test] +fn dst() { + pin_project! { + pub struct A { + x: T, + } + } -// pin_project! { -// pub struct B { -// #[pin] -// x: T, -// } -// } -// } + let _: &mut A = &mut A { x: 0u8 } as _; + + pin_project! { + pub struct B { + #[pin] + x: T, + } + } +} #[test] fn dyn_type() { diff --git a/tests/ui/invalid-bounds.rs b/tests/ui/invalid-bounds.rs new file mode 100644 index 0000000..980bb95 --- /dev/null +++ b/tests/ui/invalid-bounds.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct A { //~ ERROR no rules expected the token `:` + field: T, + } +} + +pin_project! { + struct B { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` + field: T, + } +} + +fn main() {} diff --git a/tests/ui/invalid-bounds.stderr b/tests/ui/invalid-bounds.stderr new file mode 100644 index 0000000..ebd1da8 --- /dev/null +++ b/tests/ui/invalid-bounds.stderr @@ -0,0 +1,21 @@ +error: no rules expected the token `:` + --> $DIR/invalid-bounds.rs:4:25 + | +4 | struct A { //~ ERROR no rules expected the token `:` + | ^ no rules expected this token in macro call + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> $DIR/invalid-bounds.rs:9:1 + | +9 | / pin_project! { +10 | | struct B { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +11 | | field: T, +12 | | } +13 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)