-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
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"); } ```
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1459,11 +1459,11 @@ impl<'a> State<'a> { | |
self.print_else(e.as_ref().map(|e| &**e)) | ||
} | ||
// "another else-if-let" | ||
ast::ExprIfLet(ref pat, ref expr, ref then, ref e) => { | ||
ast::ExprIfLet(ref pats, ref expr, ref then, ref e) => { | ||
try!(self.cbox(indent_unit - 1)); | ||
try!(self.ibox(0)); | ||
try!(word(&mut self.s, " else if let ")); | ||
try!(self.print_pat(&**pat)); | ||
try!(self.print_pats(pats)); | ||
try!(space(&mut self.s)); | ||
try!(self.word_space("=")); | ||
try!(self.print_expr(&**expr)); | ||
|
@@ -1497,10 +1497,10 @@ impl<'a> State<'a> { | |
self.print_else(elseopt) | ||
} | ||
|
||
pub fn print_if_let(&mut self, pat: &ast::Pat, expr: &ast::Expr, blk: &ast::Block, | ||
pub fn print_if_let(&mut self, pats: &[P<ast::Pat>], expr: &ast::Expr, blk: &ast::Block, | ||
elseopt: Option<&ast::Expr>) -> IoResult<()> { | ||
try!(self.head("if let")); | ||
try!(self.print_pat(pat)); | ||
try!(self.print_pats(pats)); | ||
try!(space(&mut self.s)); | ||
try!(self.word_space("=")); | ||
try!(self.print_expr(expr)); | ||
|
@@ -1721,8 +1721,8 @@ impl<'a> State<'a> { | |
ast::ExprIf(ref test, ref blk, ref elseopt) => { | ||
try!(self.print_if(&**test, &**blk, elseopt.as_ref().map(|e| &**e))); | ||
} | ||
ast::ExprIfLet(ref pat, ref expr, ref blk, ref elseopt) => { | ||
try!(self.print_if_let(&**pat, &**expr, &** blk, elseopt.as_ref().map(|e| &**e))); | ||
ast::ExprIfLet(ref pats, ref expr, ref blk, ref elseopt) => { | ||
try!(self.print_if_let(&**pats, &**expr, &** blk, elseopt.as_ref().map(|e| &**e))); | ||
} | ||
ast::ExprWhile(ref test, ref blk, opt_ident) => { | ||
if let Some(ident) = opt_ident { | ||
|
@@ -2253,6 +2253,19 @@ impl<'a> State<'a> { | |
self.ann.post(self, NodePat(pat)) | ||
} | ||
|
||
pub fn print_pats(&mut self, pats: &[ast::Pat]) -> IoResult<()> { | ||
let mut first = true; | ||
for ref p in pats { | ||
if first { | ||
first = false; | ||
} else { | ||
try!(space(&mut self.s)); | ||
try!(self.word_space("|")); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Manishearth
|
||
} | ||
try!(self.print_pat(&**p)); | ||
} | ||
} | ||
|
||
fn print_arm(&mut self, arm: &ast::Arm) -> IoResult<()> { | ||
// I have no idea why this check is necessary, but here it | ||
// is :( | ||
|
Should there be a space here on either side?