pin-project-lite icon indicating copy to clipboard operation
pin-project-lite copied to clipboard

Support multiple trait bounds on generics and where clause

Open taiki-e opened this issue 6 years ago • 3 comments

Workaround: https://github.com/taiki-e/pin-project-lite/issues/2#issuecomment-745190950

Currently, the following code does not be supported:

generics:

  • [x] ? trait bounds: done in #9
pin_project! { 
    pub struct Maybe<'a, T: ?Sized> {  
        field: &'a mut T, 
    } 
} 
  • [ ] multiple trait bounds:
pin_project! { 
    pub struct Multiple<'a, T: core::fmt::Debug + core::fmt::Display> { 
        field: &'a mut T, 
    } 
} 

where clause:

  • [x] ? trait bounds: done in #22
pin_project! { 
    pub struct Maybe<'a, T> 
    where
        T: ?Sized,
    { 
        field: &'a mut T, 
    } 
} 
  • [ ] multiple trait bounds:
pin_project! { 
    pub struct Multiple<'a, T> 
    where
        T: core::fmt::Debug + core::fmt::Display
    { 
        field: &'a mut T, 
    } 
} 

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

taiki-e avatar Oct 22 '19 16:10 taiki-e

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

taiki-e avatar Oct 22 '19 17:10 taiki-e

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

taiki-e avatar Jun 04 '20 18:06 taiki-e

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, 
      } 
  }

taiki-e avatar Dec 15 '20 10:12 taiki-e