-
Notifications
You must be signed in to change notification settings - Fork 15
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
UnNamed discriminant unions #31
Comments
Hm, that's pretty awkward. Rust doesn't support unnamed compound types, so we'd need to make up a name for it, and you'd have to use that name to refer to the Rust enum variants. |
Yes, I agree. But maybe we could use the name of the attribute it's prefixing? In the example above, there's an attribute named What do you think? |
It looks like anonymous types can be arbitrarily nested though:
What name would you use for the inner one? |
😱 |
@jsgf I suppose they would still potentially have a path though to the type. It appears that we already name cases based on their matched value. So what if we used that? enum SomeStruct_Value_Union_Const1_Union {
Const1,
}
enum SomeStruct_Value_Union {
Const1(SomeStruct_Value_Union_Const1_Union),
}
struct SomeStruct {
value: SomeStruct_Value_Union
} Basically, this could be a pattern like:
Not sure that maps super well, but it should be unique... It's also not pretty but we're dealing with anonymous types so perhaps we can't be too choosy. |
Ok, so the challenge is that the nom spec actually does parse these unname types fine (I was able to add a test locally) but not it appears that when we try to parse it breaks on the unnamed type. Of course, the code doesn't know that it has an unnamed type until it gets to that point and it's definitely missing from Do you think there's a way to scan for unnamed types first, like a preprocessing, and then replace the types with idents? |
This may be known behavior but it appears that un-named union types fail:
outputs:
It doesn't look like the RFC specifies that this is needed though.
The text was updated successfully, but these errors were encountered: