C-like enums and `adt_const_params`

Right now it seems like feature(adt_const_params) is largely blocked on implementing valtrees and const generics are constrained to integer-like types (including char and bool).

However, C-like enums are "integer like" and can have a specific integer repr as well. It seems like supporting them with the current implementation of const generics might be especially simple, e.g.:

#[derive(Eq, PartialEq)]
pub enum Foo {
    A = 1,
    B = 2,
    C = 3, 

pub struct Bar<const FOO: Foo> {}

In fact, this works today:

pub struct Bar<const FOO: u8> {}
pub type Baz = Bar<{Foo::A as u8}>;

However the former fails with:

error: `Foo` is forbidden as the type of a const generic parameter
  --> src/lib.rs:13:27
13 | pub struct Bar<const FOO: Foo> {}
   |                           ^^^
   = note: the only supported types are integers, `bool` and `char`

I brought this up a few days ago on Zulip. The project group is aware and has decided to not stabilize the subset. I can't figure out how to link to Zulip on mobile, but if you check the relevant channel it's quite recent.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.