-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 PatWildMulti #29486
Remove PatWildMulti #29486
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
Doesn't this also break printing of |
So does the I'm not sure if I'm too happy about the change either, from a language point of view. I feel that When you use |
(also, @sanxiyn is correct) |
I just had a look at the API again, I was wrong, PatEnum and PatStruct use a different mechanism to handle Also opened #29501 since the docs had a mistake. |
@@ -543,11 +543,6 @@ pub fn check_pat(tcx: &ty::ctxt, pat: &hir::Pat, | |||
// Foo(a, b, c) | |||
hir::PatEnum(_, Some(ref pat_fields)) => { | |||
for (field, struct_field) in pat_fields.iter().zip(&v.fields) { | |||
// a .. pattern is fine, but anything positional is |
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.
Could we preserve this comment somehow? Mention on this that when the second field is None, it's a ..
pattern, which is okay.
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.
@Manishearth
It's an erroneous comment, PatWildMulti
couldn't be here and Variant(..)
pattern is hir::PatEnum(_, 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.
It's an erroneous comment, but it addresses a real issue, that of Variant(..)
patterns.
I'm saying we move this comment up and have it talk of why PatEnum(_, None)
is ignored.
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 misread it, sorry, will add a comment now.
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.
Updated with a (pretty obvious) comment.
r=me with that nit. cc @nrc |
And yeah, it may look confusing, but it's a purely technical internal change, it doesn't break anything or change semantics. |
@bors-servo r+ rollup |
📌 Commit 306b0ef has been approved by |
Motivation: - It is not actually a pattern - It is not actually needed, except for... Drawback: - Slice patterns like `[a, _.., b]` are pretty-printed as `[a, .., b]`. Great loss :( plugin-[breaking-change], as always
I would have liked to accept only the change to the HIR and not change the AST. There is no requirement that the HIR can be round-tripped via pretty printing or even that pretty printed HIR is compilable, so simplification there is welcome. However, it is a goal of the AST to be as close as possible to the source text - if there is different source text (which is the case here) then this should be reflected in the AST. I expect the AST to move more in this direction in the future (one could imagine a syntax extension which adds semantic differences here where there are none in Rust). I'd prefer to see the AST change reversed (unless I'm misunderstanding), but it is pretty minor, so I don't think it is too important for now (I expect that we will revamp the AST in the future anyway). |
@nrc Instead of reversing the AST change, perhaps we should add a bool flag to PatVec, to be in line with the other places |
In general I prefer enums to bools since the names are more informative/documenting, but consistency is important, so that would work for me. |
To what extent is AST supposed to mirror the source text? Currently, for example, presence of trailing separators in various lists isn't tracked in AST but at the same time affects pretty-printing. |
@petrochenkov "supposed" is hard to answer because the role of the AST is in flux. In the past it was used by the frontend, tools, syntax extensions, and the compiler so there was a trade-off between being easy to parse, easy to operate on syntactically, and concise so the compiler can operate on it most easily. We have no separated out the AST and HIR so the HIR can be optimised for the compiler and maximally concise (this PR being an example of exactly the kind of change I want to see in the HIR). While the AST is focussed more on being easily usable in tools and syntax extensions - that means (I think) being closer to the source text than it is currently (for example, I want to be able to find comments in the AST). Pretty printing is one example of a tool that needs close correspondence between the AST and source. So, I would like to aim for '100%' correspondence between the source and AST even though that is not the current state, nor has it been a goal in the past. Note on '100%' and trailing separators. I haven't thought in detail about how the AST should represent these kind of details - I don't think comments should be in the AST, and nor should trailing separators (probably). I am considering some kind of model where we keep the token stream around and support easy indexing of the token stream from the AST (we would also move all span info to the token stream and out of the AST). Then that kind of syntactic trivia is not in the AST, but easily accessible from it. As I haven't figured out the detail of the design, I'm not sure whether PartWildMulti is something best expressed by this method or directly in the AST |
This reminds me of some of the zero copy and tendril work that was being done for html5ever. |
Motivation:
Drawback:
[a, _.., b]
are pretty-printed as[a, .., b]
. Great loss :(plugin-[breaking-change], as always