Skip to content

Commit c2a81c2

Browse files
lilyballJakub Wieczorek
authored andcommitted
---
yaml --- r: 136819 b: refs/heads/dist-snap c: 0e6ff43 h: refs/heads/master i: 136817: e6f0bd0 136815: abd238f v: v3
1 parent 411dc3f commit c2a81c2

File tree

10 files changed

+109
-2
lines changed

10 files changed

+109
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 189b7332968972f34cdbbbd9b62d97ababf53059
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 5d8cfd53b513d999ffff22f17e3066a30a8ed949
9+
refs/heads/dist-snap: 0e6ff432dc83e5675163b1c29ce73dbc5e18ba24
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
222222
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
223223
}
224224

225+
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
226+
225227
ast::ExprWhile(ref cond, ref body, _) => {
226228
//
227229
// [pred]

branches/dist-snap/src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
374374
}
375375
}
376376

377+
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
378+
377379
ast::ExprMatch(ref discr, ref arms) => {
378380
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));
379381
self.borrow_expr(&**discr, ty::ReEmpty, ty::ImmBorrow, MatchDiscriminant);

branches/dist-snap/src/librustc/middle/liveness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
481481
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
482482
visit::walk_expr(ir, expr);
483483
}
484+
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
484485
ExprForLoop(ref pat, _, _, _) => {
485486
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
486487
debug!("adding local variable {} from for loop with bm {:?}",
@@ -1011,6 +1012,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10111012
self.propagate_through_expr(&**cond, ln)
10121013
}
10131014

1015+
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
1016+
10141017
ExprWhile(ref cond, ref blk, _) => {
10151018
self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ)
10161019
}
@@ -1470,6 +1473,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14701473
ExprPath(..) | ExprBox(..) => {
14711474
visit::walk_expr(this, expr);
14721475
}
1476+
ExprIfLet(..) => fail!("non-desugared ExprIfLet")
14731477
}
14741478
}
14751479

branches/dist-snap/src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
505505
ast::ExprForLoop(..) => {
506506
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
507507
}
508+
509+
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet")
508510
}
509511
}
510512

branches/dist-snap/src/librustc/middle/trans/debuginfo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,11 @@ fn populate_scope_map(cx: &CrateContext,
35763576
}
35773577
}
35783578

3579+
ast::ExprIfLet(..) => {
3580+
cx.sess().span_bug(exp.span, "debuginfo::populate_scope_map() - \
3581+
Found unexpanded if-let.");
3582+
}
3583+
35793584
ast::ExprWhile(ref cond_exp, ref loop_body, _) => {
35803585
walk_expr(cx, &**cond_exp, scope_stack, scope_map);
35813586

branches/dist-snap/src/librustc/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,6 +3634,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
36343634
ast::ExprLit(ref lit) if lit_is_str(&**lit) => {
36353635
RvalueDpsExpr
36363636
}
3637+
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
36373638

36383639
ast::ExprCast(..) => {
36393640
match tcx.node_types.borrow().find(&(expr.id as uint)) {

branches/dist-snap/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
41064106
check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.as_ref().map(|e| &**e),
41074107
id, expr.span, expected);
41084108
}
4109+
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
41094110
ast::ExprWhile(ref cond, ref body, _) => {
41104111
check_expr_has_type(fcx, &**cond, ty::mk_bool());
41114112
check_block_no_value(fcx, &**body);

branches/dist-snap/src/librustc_back/svh.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ mod svh_visitor {
293293
ExprForLoop(..) => SawExprForLoop,
294294

295295
// just syntactic artifacts, expanded away by time of SVH.
296+
ExprIfLet(..) => unreachable!(),
296297
ExprMac(..) => unreachable!(),
297298
}
298299
}

branches/dist-snap/src/libsyntax/ext/expand.rs

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
3939
e.and_then(|ast::Expr {id, node, span}| match node {
4040
// expr_mac should really be expr_ext or something; it's the
4141
// entry-point for all syntax extensions.
42-
ExprMac(mac) => {
42+
ast::ExprMac(mac) => {
4343
let expanded_expr = match expand_mac_invoc(mac, span,
4444
|r| r.make_expr(),
4545
mark_expr, fld) {
@@ -67,6 +67,95 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
6767
fld.cx.expr(span, ast::ExprWhile(cond, body, opt_ident))
6868
}
6969

70+
// Desugar ExprIfLet
71+
// From: `if let <pat> = <expr> <body> [<elseopt>]`
72+
ast::ExprIfLet(pat, expr, body, mut elseopt) => {
73+
let span = e.span;
74+
75+
// to:
76+
//
77+
// match <expr> {
78+
// <pat> => <body>,
79+
// [_ if <elseopt_if_cond> => <elseopt_if_body>,]
80+
// _ => [<elseopt> | ()]
81+
// }
82+
83+
// `<pat> => <body>`
84+
let pat_arm = {
85+
let body_expr = fld.cx.expr_block(body);
86+
fld.cx.arm(pat.span, vec![pat], body_expr)
87+
};
88+
89+
// `[_ if <elseopt_if_cond> => <elseopt_if_body>,]`
90+
let else_if_arms = {
91+
let mut arms = vec![];
92+
loop {
93+
// NOTE: replace with 'if let' after snapshot
94+
match elseopt {
95+
Some(els) => match els.node {
96+
// else if
97+
ast::ExprIf(cond, then, elseopt_) => {
98+
let pat_under = fld.cx.pat_wild(span);
99+
elseopt = elseopt_;
100+
arms.push(ast::Arm {
101+
attrs: vec![],
102+
pats: vec![pat_under],
103+
guard: Some(cond),
104+
body: fld.cx.expr_block(then)
105+
});
106+
}
107+
_ => break
108+
},
109+
None => break
110+
}
111+
}
112+
arms
113+
};
114+
115+
// `_ => [<elseopt> | ()]`
116+
let else_arm = {
117+
let pat_under = fld.cx.pat_wild(span);
118+
let else_expr = match elseopt {
119+
Some(els) => els,
120+
None => fld.cx.expr_lit(span, ast::LitNil)
121+
};
122+
fld.cx.arm(span, vec![pat_under], else_expr)
123+
};
124+
125+
let mut arms = Vec::with_capacity(else_if_arms.len() + 2);
126+
arms.push(pat_arm);
127+
arms.push_all_move(else_if_arms);
128+
arms.push(else_arm);
129+
130+
let match_expr = fld.cx.expr_match(span, expr, arms);
131+
fld.fold_expr(match_expr)
132+
}
133+
134+
// Desugar support for ExprIfLet in the ExprIf else position
135+
ast::ExprIf(cond, blk, mut elseopt) => {
136+
// NOTE: replace with 'if let' after snapshot
137+
match elseopt {
138+
Some(els) => match els.node {
139+
ast::ExprIfLet(..) => {
140+
// wrap the if-let expr in a block
141+
let blk = P(ast::Block {
142+
view_items: vec![],
143+
stmts: vec![],
144+
expr: Some(els),
145+
id: ast::DUMMY_NODE_ID,
146+
rules: ast::DefaultBlock,
147+
span: els.span
148+
});
149+
elseopt = Some(fld.cx.expr_block(blk));
150+
}
151+
_ => ()
152+
},
153+
None => ()
154+
};
155+
let if_expr = fld.cx.expr(e.span, ast::ExprIf(cond, blk, elseopt));
156+
noop_fold_expr(if_expr, fld)
157+
}
158+
70159
ast::ExprLoop(loop_block, opt_ident) => {
71160
let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld);
72161
fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident))

0 commit comments

Comments
 (0)