-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Clairify ast::PatKind::Struct
presese of ..
by using an enum instead of a bool
#119231
Conversation
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.
This looks good to me, but I wonder if we could make it better
compiler/rustc_ast/src/ast.rs
Outdated
/// The `bool` is `true` in the presence of a `..`. | ||
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, /* recovered */ bool), | ||
/// The `bool` is `true` in the presence of a `..` (or when recovered). | ||
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, bool), |
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.
Please either convert this into:
Struct {
qself: Option<P<QSelf>>,
path: Path,
fields: ThinVec<PatField>,
// Whether `..` is meant to capture the rest of the tuple fields
rest: bool,
}
Or alternatively, change the bool into an enum like StructRest
is used in StructExpr
:
enum PatFieldsRest {
Rest,
None,
}
Do you think you could do either of these? I have no preference which, but I think we could do better 😸
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 the latter is preferable, as it also clarifies it in the return type in the parser.
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.
Should I make the same change in HIR? Or can I leave that as a potential followup commit?
5627b0e
to
2b620be
Compare
ast::PatKind::Struct
docs.ast::PatKind::Struct
presese of ..
by using an enum instead of a bool
Could not assign reviewer from: |
Pushed a version using the enum approach, only in the AST. |
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.
r=me when it's green
@@ -82,7 +82,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |||
span: self.lower_span(f.span), | |||
} | |||
})); | |||
break hir::PatKind::Struct(qpath, fs, *etc); | |||
break hir::PatKind::Struct(qpath, fs, *etc == ast::PatFieldsRest::Rest); |
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.
a follow-up perhaps
This comment has been minimized.
This comment has been minimized.
2b620be
to
af149df
Compare
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
Pushed a fix to tools. Should I add |
src/tools/rustfmt/src/patterns.rs
Outdated
@@ -324,7 +327,7 @@ fn rewrite_struct_pat( | |||
|
|||
let has_trailing_comma = fmt.needs_trailing_separator(); | |||
|
|||
if ellipsis { | |||
if ellipsis == ast::PatFieldsRest::None { |
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.
This is wrong
Nah I think it's fine |
This comment has been minimized.
This comment has been minimized.
af149df
to
03bed27
Compare
thanks! @bors r+ |
sorry about making you review changes that i should have figured were broken here. i'll try to be less careless and make sure everything builds before opening next time |
This comment was marked as off-topic.
This comment was marked as off-topic.
03bed27
to
1349d86
Compare
@bors r+ |
…docs, r=compiler-errors Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. r? `@compiler-errors`
…iaskrgr Rollup of 2 pull requests Successful merges: - rust-lang#119072 (Clean up `check_consts` and misc fixes) - rust-lang#119231 (Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#119231 (Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool) - rust-lang#119232 (Fix doc typos) - rust-lang#119245 (Improve documentation for using warning blocks in documentation) - rust-lang#119248 (remove dead inferred outlives testing code) - rust-lang#119249 (Add spastorino to users_on_vacation) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. r? ``@compiler-errors``
…docs, r=compiler-errors Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. r? ``@compiler-errors``
…docs, r=compiler-errors Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. r? ``@compiler-errors``
The bool is mainly used for when a
..
is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.See
rust/compiler/rustc_parse/src/parser/pat.rs
Lines 890 to 897 in cee794e
r? @compiler-errors