-
Notifications
You must be signed in to change notification settings - Fork 13.5k
syntax: Merge parsing code for structures and variants #29714
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
// For style and consistency reasons, non-parametrized enum variants must | ||
// be used simply as `ident` instead of `ident ()`. | ||
// This test-case covers enum declaration. | ||
|
||
enum Foo { | ||
Bar(), //~ ERROR nullary enum variants are written with no trailing `( )` | ||
Baz(), //~ ERROR nullary enum variants are written with no trailing `( )` | ||
Bar(), //~ ERROR empty tuple structs and enum variants are not allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is pretty major regression to the error message. It was pretty clearly pointing out at the mistake before and telling how to fix it. Now it seems to suggest it is not allowed altogether, although only the syntax is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a note then "note: Remove the trailing ()
". Good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuple structs and enum variants with zero fields are indeed not allowed altogether, it's not just syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a “help: remove trailing () if you meant to write empty enum variant” would be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
r? @nrc |
@@ -867,6 +867,8 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { | |||
self.context.span_handler.span_err(span, "empty tuple structs and enum variants \ | |||
are not allowed, use unit structs and \ | |||
enum variants instead"); | |||
self.context.span_handler.span_help(span, "remove trailing `()` if you meant to \ | |||
write empty enum variant or structure"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The language here is a little bit confusing I would change to "remove trailing ()
to make a unit struct or unit enum variant" as the terminology then matches the error message.
067f520
to
2a01e26
Compare
r+ with the enum for bool and typos in the error message fixed. |
9c17ad7
to
4f1d9ee
Compare
4f1d9ee
to
649fc38
Compare
Updated. |
Thanks! @bors: r+ |
📌 Commit 649fc38 has been approved by |
In particular, attributes are now parsed on fields of tuple variants
In particular, attributes are now parsed on fields of tuple variants