taiki-e / pin-project-lite

A lightweight version of pin-project written with declarative macros.
https://docs.rs/pin-project-lite
Apache License 2.0
216 stars 15 forks source link

Support multiple trait bounds on generics and where clause #2

Open taiki-e opened 4 years ago

taiki-e commented 4 years ago

Currently, the following code does not be supported:

generics:

where clause:

pin_project! { 
    pub struct Maybe<'a, T> 
    where
        T: ?Sized,
    { 
        field: &'a mut T, 
    } 
} 

reference: https://doc.rust-lang.org/reference/trait-bounds.html#trait-and-lifetime-bounds

taiki-e commented 4 years ago

This is a bug, but maybe a limitation of declarative macros, and I'm not sure if it can be fully fixed.

taiki-e commented 4 years ago

? trait bounds are supported on both generics and where clause. (#9, #22)

taiki-e commented 3 years ago

Workaround: This can be avoided by moving bounds to where clause and splitting it.

  pin_project! { 
-     pub struct Multiple<'a, T: core::fmt::Debug + core::fmt::Display> { 
+     pub struct Multiple<'a, T: core::fmt::Debug> 
+     where
+        T: core::fmt::Display,
      { 
          field: &'a mut T, 
      } 
  }
  pin_project! { 
      pub struct Multiple<'a, T> 
      where
-         T: core::fmt::Debug + core::fmt::Display
+         T: core::fmt::Debug,
+         T: core::fmt::Display,
      { 
          field: &'a mut T, 
      } 
  }