-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix #[derive] for empty tuple structs/variants #35728
Conversation
@@ -844,7 +844,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { | |||
} | |||
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> { | |||
let pat = if subpats.is_empty() { | |||
PatKind::Path(None, path) | |||
PatKind::Struct(path, Vec::new(), false) |
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.
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.
Alternatively I can change interface of the builder and split pat_enum
into pat_path
/pat_tuple_struct
, that would be a more disruptive change.
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.
Serde does not use PatKind so we are not affected.
I don't understand this method. Below, pat_struct produces PatKind::Struct and pat_tuple produces PatKind::Tuple. Why does pat_enum mean PatKind::TupleStruct? Can't enum variants be structs too? Also for the empty case why pick empty PatKind::Struct over empty PatKind::TupleStruct?
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.
Why does pat_enum mean PatKind::TupleStruct? Can't enum variants be structs too?
The name pat_enum
is pretty old, from times when braced enum variants Variant{..}
were unstable and empty braced structs/variants Variant{}
didn't exist, it means either TupleVariant(..)
or UnitVariant
.
Also for the empty case why pick empty PatKind::Struct over empty PatKind::TupleStruct?
Because it matches anything (see rust-lang/rfcs#1506 for more details).
The alternative I mentioned above (pat_enum
-> pat_path
/pat_tuple_struct
) is much cleaner at cost of larger breakage. I will probably implement it instead.
r=me |
8a0ad66
to
f6e06a8
Compare
Updated with |
Fix #[derive] for empty tuple structs/variants This was missing from rust-lang#35138
Batch up libsyntax breaking changes Batch of the following syntax-[breaking-change] changes: - #35591: Add a field `span: Span` to `ast::Generics`. - #35618: Remove variant `Mod` of `ast::PathListItemKind` and refactor the remaining variant `ast::PathListKind::Ident` to a struct `ast::PathListKind_`. - #35480: Change uses of `Constness` in the AST to `Spanned<Constness>`. - c.f. `MethodSig`, `ItemKind` - #35728: Refactor `cx.pat_enum()` into `cx.pat_tuple_struct()` and `cx.pat_path()`. - #35850: Generalize the elements of lists in attributes from `MetaItem` to a new type `NestedMetaItem` that can represent a `MetaItem` or a literal. - #35917: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`. - Besides removing imports of these traits, this won't cause fallout. - Add a variant `Union` to `ItemKind` to future proof for `union` (c.f. #36016). - Remove inherent methods `attrs` and `fold_attrs` of `Annotatable`. - Use methods `attrs` and `map_attrs` of `HasAttrs` instead. r? @Manishearth
This was missing from #35138
plugin-[breaking-change]
r? @Manishearth