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

Derive macros fail with new "explicit discriminants on enums with fields" #606

Closed
timwie opened this issue Dec 15, 2022 · 1 comment · Fixed by #626
Closed

Derive macros fail with new "explicit discriminants on enums with fields" #606

timwie opened this issue Dec 15, 2022 · 1 comment · Fixed by #626

Comments

@timwie
Copy link

timwie commented Dec 15, 2022

Rust 1.66 was just released, along with Explicit discriminants on enums with fields. The given example does not compile when adding bincode (2.0.0-rc.2) derive macros to the enum:

$ cargo -V
# cargo 1.66.0 (d65d197ad 2022-11-15)
#[derive(Decode, Encode)]
#[repr(u8)]
enum Foo {
    A(u8),
    B(i8),
    C(bool) = 42,
}

# error: Invalid rust syntax, expected ident, got Some(Punct { ch: '=', spacing: Alone, span: #0 bytes(334..335) })
@VictorKoenders
Copy link
Contributor

Step 1 would be to implement this in virtue: issue

After that we should see how serde implements this. With normal discriminants serde does not actually respect the value. e.g.

enum Foo {
    A = 5,
    B = 3,
}

Will still be encoded as 0 and 1 (See #592 for the reason why). I suspect this new syntax will also not actually respect the values, but instead use the index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants