diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 303277afbe8..6ef938030ff 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -137,15 +137,16 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { // to: // - // { - // let _i = &mut <src_expr>; - // ['<ident>:] loop { - // match i.next() { + // match &mut <src_expr> { + // i => { + // ['<ident>:] loop { + // match i.next() { // None => break, // Some(<src_pat>) => <src_loop_block> + // } // } + // } // } - // } let local_ident = token::gensym_ident("i"); let next_ident = fld.cx.ident_of("next"); @@ -154,10 +155,6 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { let local_path = fld.cx.path_ident(span, local_ident); let some_path = fld.cx.path_ident(span, fld.cx.ident_of("Some")); - // `let i = &mut <src_expr>` - let iter_decl_stmt = fld.cx.stmt_let(span, false, local_ident, - fld.cx.expr_mut_addr_of(span, src_expr)); - // `None => break ['<ident>];` let none_arm = { // FIXME #6993: this map goes away: @@ -185,16 +182,13 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { ast::ExprLoop(fld.cx.block_expr(match_expr), opt_ident)); - // `{ let ... ; loop { ... } }` - let block = fld.cx.block(span, - ~[iter_decl_stmt], - Some(loop_expr)); + // `i => loop { ... }` - @ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprBlock(block), - span: span, - } + // `match &mut <src_expr> { i => loop { ... } }` + let discrim = fld.cx.expr_mut_addr_of(span, src_expr); + let i_pattern = fld.cx.pat_ident(span, local_ident); + let arm = fld.cx.arm(span, ~[i_pattern], loop_expr); + fld.cx.expr_match(span, discrim, ~[arm]) } _ => noop_fold_expr(e, fld) |
