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

syn::parse_item fails to parse enum with custom values #12

Closed
hauleth opened this issue Sep 18, 2016 · 2 comments
Closed

syn::parse_item fails to parse enum with custom values #12

hauleth opened this issue Sep 18, 2016 · 2 comments

Comments

@hauleth
Copy link

hauleth commented Sep 18, 2016

syn fails to parse valid enum like https://is.gd/bsNmUd. This is blocking issue for num-macros to work with syn.

@dtolnay
Copy link
Owner

dtolnay commented Sep 20, 2016

Sorry for the slow response - I am on vacation this week without internet access. This will be my highest priority when I get back on Friday, unless someone has a PR ready by then.

@dtolnay
Copy link
Owner

dtolnay commented Sep 24, 2016

I fixed this in 0.6.0. Variants now have an optional discriminant field so your example looks like this:

enum Foo {
    A = 1,
    B = 2,
    C
}

MacroInput {
    ident: "Foo".into(),
    vis: Visibility::Inherited,
    attrs: vec![],
    generics: Generics::default(),
    body: Body::Enum(vec![
        Variant {
            ident: "A".into(),
            attrs: vec![],
            data: VariantData::Unit,
            discriminant: Some(Discriminant {
                value: 1,
                ty: IntTy::Unsuffixed,
            }),
        },
        Variant {
            ident: "B".into(),
            attrs: vec![],
            data: VariantData::Unit,
            discriminant: Some(Discriminant {
                value: 2,
                ty: IntTy::Unsuffixed,
            }),
        },
        Variant {
            ident: "C".into(),
            attrs: vec![],
            data: VariantData::Unit,
            discriminant: None,
        },
    ]),
}

@dtolnay dtolnay closed this as completed Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants