-
Notifications
You must be signed in to change notification settings - Fork 13k
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
If while let multiple patterns #23034
If while let multiple patterns #23034
Conversation
This commit adds support for multiple patterns in if-let statements: ```rust let x = Some(0); if let Some(0) | Some(1) = x { println!("Got 0 or 1"); } ```
This just tests very basic usage.
This mirrors 3da6cf5
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
Update grammar.md to reflect the changes to `if let` and `while let`.
RfC: rust-lang/rfcs#937 |
☔ The latest upstream changes (presumably #22873) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -2253,6 +2253,20 @@ impl<'a> State<'a> { | |||
self.ann.post(self, NodePat(pat)) | |||
} | |||
|
|||
pub fn print_pats(&mut self, pats: &[P<ast::Pat>]) -> io::Result<()> { | |||
let mut first = true; |
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.
nit:
match pats {
[] => {},
[p, ..ps] => {
try!(self.print_pat(&**p));
for p in ps {
try!(space(&mut self.s));
try!(self.word_space("|"));
try!(self.print_pat(&**p));
}
}
}
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.
Here you go: d570bac
As per @tamird's suggestion.
☔ The latest upstream changes (presumably #23473) made this pull request unmergeable. Please resolve the merge conflicts. |
Given that the RFC wasn't accepted, I'm giving this PR a close. |
This is a pull request for adding support for multiple patterns in
if let
andwhile let
statements.It feels like a natural extension to the current functionality, and it's a trouble-free addition to the language.
I'm currently writing up an RFC for this change.