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

Support const generics

Open taiki-e opened this issue 4 years ago • 4 comments

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).

taiki-e avatar Jul 21 '21 12:07 taiki-e

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?

jjl avatar Jul 21 '21 12:07 jjl

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

taiki-e avatar Jul 21 '21 13:07 taiki-e

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.

notgull avatar Mar 30 '24 03:03 notgull

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.

jjl avatar Mar 30 '24 08:03 jjl