Skip to content
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

Closed

Conversation

Munksgaard
Copy link
Contributor

This is a pull request for adding support for multiple patterns in if let and while 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.

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.
@rust-highfive
Copy link
Collaborator

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`.
@Manishearth
Copy link
Member

RfC: rust-lang/rfcs#937

@bors
Copy link
Contributor

bors commented Mar 5, 2015

☔ 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;
Copy link
Contributor

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));
    }
  }
}

Copy link
Contributor Author

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.
@bors
Copy link
Contributor

bors commented Mar 18, 2015

☔ The latest upstream changes (presumably #23473) made this pull request unmergeable. Please resolve the merge conflicts.

@steveklabnik
Copy link
Member

Given that the RFC wasn't accepted, I'm giving this PR a close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants