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

remove empty field list in unions #496

Merged
merged 3 commits into from
Jun 7, 2024

Conversation

nefelitav
Copy link
Contributor

Rust unions cannot have zero fields, in contrast to enums and structs. (https://github.com/ferrocene/ferrocene/blob/main/tests/ui/union/union-empty.rs)

@Veykril
Copy link
Member

Veykril commented Jun 7, 2024

Good catch! Though this is a semantic restriction, not a syntactic one (that is macros can observe the syntax still), as can be seen by the following compiling https://play.rust-lang.org/?version=stable&mode=debug&edition=2021

Could you phrase this as a legality rule? (like is done for unsafe tokens for modules in https://spec.ferrocene.dev/program-structure-and-compilation.html#fls_whgv72emrm47)

@nefelitav
Copy link
Contributor Author

Good catch! Though this is a semantic restriction, not a syntactic one (that is macros can observe the syntax still), as can be seen by the following compiling https://play.rust-lang.org/?version=stable&mode=debug&edition=2021

Could you phrase this as a legality rule? (like is done for unsafe tokens for modules in https://spec.ferrocene.dev/program-structure-and-compilation.html#fls_whgv72emrm47)

Thank you for the feedback and the clarification! It seems there might have been an issue with the link you provided on the playground. Could you please resend it?

Also, based on my understanding of the Rust Reference, it seems like the Union Syntax requires at least one field, in contrast to Struct and Enum. Could you please confirm if this is correct?

@Veykril
Copy link
Member

Veykril commented Jun 7, 2024

@Veykril
Copy link
Member

Veykril commented Jun 7, 2024

Reading through the reference, it seems to actually not describe this restriction at all. The grammar lists StructFields like we do, but they are also lacking a phrasing that requires at least on field in the declaration.

@nefelitav
Copy link
Contributor Author

Reading through the reference, it seems to actually not describe this restriction at all. The grammar lists StructFields like we do, but they are also lacking a phrasing that requires at least on field in the declaration.

Thank you for the link! I apologize in advance if I'm wrong, but I still think the Reference syntax is different from the Ferrocene one. In the reference, for unions, there is no "?" after the StructFields, while for structs and enums there is a "?", showing that fields are optional. And StructFields are defined like this:

StructFields :
StructField (, StructField)* ,?

So, I think that according to the Reference syntax, there should be at least one StructField in unions .

@Veykril
Copy link
Member

Veykril commented Jun 7, 2024

Ah I see, I didn't look at the definition of StructFields properly, in that case the reference is wrong given you can have zero fields in the grammar as shown by my snippet. It is a semantic rule, not syntactic, so both documents are missing the semantic rule disallowing this state post macro expansion.

@nefelitav
Copy link
Contributor Author

Ah I see, I didn't look at the definition of StructFields properly, in that case the reference is wrong given you can have zero fields in the grammar as shown by my snippet. It is a semantic rule, not syntactic, so both documents are missing the semantic rule disallowing this state post macro expansion.

Thank you for the explanation! I hope it is okay now.

@Veykril
Copy link
Member

Veykril commented Jun 7, 2024

Sounds good, thanks!
bors merge

@bors-ferrocene
Copy link
Contributor

bors-ferrocene bot commented Jun 7, 2024

Build succeeded:

@bors-ferrocene bors-ferrocene bot merged commit 011a329 into ferrocene:main Jun 7, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants