Support const generics
Currently the following code fails to compile:
pin_project_lite::pin_project! {
struct S<const N: usize> {
f: [u8; N],
}
}
error: no rules expected the token `[`
--> tests/test.rs:16:5
|
16 | / pin_project! {
17 | | struct S<const N: usize> {
18 | | f: [u8; N],
19 | | }
20 | | }
| |_____^ no rules expected this token in macro call
|
= note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info)
Originally found by @jjl (https://twitter.com/techpractical/status/1415215677225553922).
Oh sorry, I assumed it was a known limitation, or I would have filed a ticket.
I assume the restriction on not being able to implement Drop is desired though?
I assume the restriction on not being able to implement Drop is desired though?
I think this issue is purely a bug of the generics parsing.
https://github.com/taiki-e/pin-project-lite/blob/ac4096c3bb574aa6be77f3c06f54509b8f707582/src/lib.rs#L1555-L1561
I took a run at this; it turns out it's a lot harder to parse arbitrary generics using nothing but declarative macros. I'll take another run at it later.
i had a go (in 2021 apparently!) and decided it was probably impossible with macros as they are. if it isn't, i couldn't figure it out anyway.