Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2535, 2530, 2175, "Or patterns, i.e `Foo(Bar(x) | Baz(x))`" #54883
Comments
Centril
added
B-RFC-approved
T-lang
C-tracking-issue
labels
Oct 7, 2018
This was referenced Oct 7, 2018
This comment has been minimized.
This comment has been minimized.
|
I've closed #48215 in favor of this issue to track all related changes since rust-lang/rfcs#2535 subsumes RFC 2175. I would suggest that |
Centril
referenced this issue
Oct 7, 2018
Closed
Variable labeling of complex match arms should be able to label the whole arm #673
This comment has been minimized.
This comment has been minimized.
|
Minor thing that I just noticed: anonymous enums with the syntax of "tuple-but- |
This comment has been minimized.
This comment has been minimized.
|
@CAD97 example of a snippet that would show the ambiguity? |
This comment has been minimized.
This comment has been minimized.
|
I confused things between patterns and types: match it {
it: (A|B) => (), // it with type ascription (A|B)
it @ (A|B) => (), // it binding to pattern (A|B)
}So long as patterns and types aren't valid in the same position, this is ok. (I confused myself since tuples are valid patterns.) |
varkor
self-assigned this
Oct 18, 2018
This comment has been minimized.
This comment has been minimized.
|
I've got a branch for this that I think is close, but as I'm quite busy at the moment, I'm not sure how soon I'll finish it; if anyone else would like to take this over in the meantime, just leave a comment. |
This comment has been minimized.
This comment has been minimized.
|
@varkor Where's your branch? I'm happy to take over if you like... especially if it gets const generics to land any sooner. ;-) |
This comment has been minimized.
This comment has been minimized.
|
@alexreg: it's at https://github.com/varkor/rust/tree/or-patterns. I think where I left it, there was some crash when you tried using or-patterns, but most of the boilerplate is in. Feel free to play around with it to see if you can get it working. (Though I'm not prioritising this over const generics, don't worry |
This comment has been minimized.
This comment has been minimized.
|
@dlrobertson BTW, have you taken into account the unresolved questions whilst working on this? |
This comment has been minimized.
This comment has been minimized.
|
@alexreg thanks for the ping. Haven't really thought about it too much. I've mostly been experimenting with the code, but at this point I am not keen on changing more than the pattern matching code for the following reasons:
That being said, I'm still new, so I might be missing something. |
This comment has been minimized.
This comment has been minimized.
|
@dlrobertson Thanks for working on this. The more important part to test with crater is whether I think it's also worth considering |
This comment has been minimized.
This comment has been minimized.
|
@dlrobertson That's fair enough. What @Centril said is good advice. |
This comment has been minimized.
This comment has been minimized.
|
Back to looking at this. An update for anyone following this (and a note to self so I don't forget things). TODO:
|
Centril commentedOct 7, 2018
This is a tracking issue for the RFC "Or patterns, i.e
Foo(Bar(x) | Baz(x))" (rust-lang/rfcs#2535).This issue also tracks the changes in rust-lang/rfcs#2175 and rust-lang/rfcs#2530 since RFC 2535 subsume those.
Steps:
Unresolved questions:
Should we allow
top_patorpat<allow_top_alt>ininferrable_paramsuch that closures permit|Ok(x) | Err(x)|without first wrapping in parenthesis?We defer this decision to stabilization as it may depend on experimentation. Our current inclination is to keep the RFC as-is because the ambiguity is not just for the compiler; for humans, it is likely also ambiguous and thus harder to read.
This also applies to functions which, although do not look as ambiguous, benefit from better consistency with closures. With respect to function arguments there's also the issue that not disambiguating with parenthesis makes it less clear whether the type ascription applies to the or-pattern as a whole or just the last alternative.
Should the
patmacro fragment specifier matchtop_patin differentRust editions or should it match
pat<no_top_alt>as currently specified? We defer such decisions to stabilization because it depends on the outcome of crater runs to see what the extent of the breakage would be.The benefit of avoiding
pat<no_top_alt>in as many places as possible would both be grammatical consistency and fewer surprises for uses. The drawbacks would be possible ambiguity or backtracking for closures and breakage for macros.