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 const generics #62

Open
taiki-e opened this issue Jul 21, 2021 · 4 comments
Open

Support const generics #62

taiki-e opened this issue Jul 21, 2021 · 4 comments
Labels
C-enhancement Category: A new feature or an improvement for an existing one help wanted Call for participation: Help is requested to fix this issue

Comments

@taiki-e
Copy link
Owner

taiki-e commented Jul 21, 2021

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 taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Jul 21, 2021
@jjl
Copy link

jjl commented Jul 21, 2021

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?

@taiki-e
Copy link
Owner Author

taiki-e commented Jul 21, 2021

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.

pin-project-lite/src/lib.rs

Lines 1555 to 1561 in ac4096c

$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
$( $generics:ident
$(: $generics_bound:path)?
$(: ?$generics_unsized_bound:path)?
$(: $generics_lifetime_bound:lifetime)?
$(= $generics_default:ty)?
),* $(,)?

@taiki-e taiki-e added the help wanted Call for participation: Help is requested to fix this issue label Jul 21, 2021
@notgull
Copy link

notgull commented Mar 30, 2024

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.

@jjl
Copy link

jjl commented Mar 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one help wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

No branches or pull requests

3 participants