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

Support multiple trait bounds on generics and where clause #2

Open
2 of 4 tasks
taiki-e opened this issue Oct 22, 2019 · 3 comments
Open
2 of 4 tasks

Support multiple trait bounds on generics and where clause #2

taiki-e opened this issue Oct 22, 2019 · 3 comments
Labels
C-bug Category: related to a bug. help wanted Call for participation: Help is requested to fix this issue

Comments

@taiki-e
Copy link
Owner

taiki-e commented Oct 22, 2019

Currently, the following code does not be supported:

generics:

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:

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 taiki-e added C-bug Category: related to a bug. C-enhancement Category: A new feature or an improvement for an existing one labels Oct 22, 2019
@taiki-e
Copy link
Owner Author

taiki-e commented Oct 22, 2019

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

@taiki-e taiki-e added the help wanted Call for participation: Help is requested to fix this issue label Oct 22, 2019
bors bot added a commit that referenced this issue Jan 20, 2020
9: Support ?Sized bounds in generic parameters r=taiki-e a=taiki-e

part of #2

Co-authored-by: Taiki Endo <[email protected]>
bors bot added a commit that referenced this issue Jan 20, 2020
9: Support ?Sized bounds in generic parameters r=taiki-e a=taiki-e

part of #2

Co-authored-by: Taiki Endo <[email protected]>
bors bot added a commit that referenced this issue Jun 4, 2020
22: Support ?Sized bounds in where clauses r=taiki-e a=taiki-e

a part of #2

Co-authored-by: Taiki Endo <[email protected]>
@taiki-e taiki-e removed help wanted Call for participation: Help is requested to fix this issue C-enhancement Category: A new feature or an improvement for an existing one labels Jun 4, 2020
@taiki-e
Copy link
Owner Author

taiki-e commented Jun 4, 2020

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

@taiki-e taiki-e changed the title Cannot support multiple trait bounds and ? trait bounds on generics and where clause Cannot support multiple trait bounds on generics and where clause Jun 4, 2020
@taiki-e taiki-e added the help wanted Call for participation: Help is requested to fix this issue label Nov 13, 2020
@taiki-e
Copy link
Owner Author

taiki-e commented Dec 15, 2020

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 taiki-e changed the title Cannot support multiple trait bounds on generics and where clause Support multiple trait bounds on generics and where clause Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: related to a bug. help wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

No branches or pull requests

1 participant