Skip to content

Commit a33512d

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 177654 b: refs/heads/tmp c: 9fdc0ef h: refs/heads/master v: v3
1 parent 0988755 commit a33512d

File tree

10 files changed

+116
-116
lines changed

10 files changed

+116
-116
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: a65d3f5b98cc94f0a759fbf1a08be9aee0f97883
37+
refs/heads/tmp: 9fdc0effd292b097ae487ec4d927ca15102c5791

branches/tmp/src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -264,42 +264,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
264264
}
265265

266266
ast::ExprForLoop(ref pat, ref head, ref body, _) => {
267-
//
268-
// [pred]
269-
// |
270-
// v 1
271-
// [head]
272-
// |
273-
// v 2
274-
// [loopback] <--+ 7
275-
// | |
276-
// v 3 |
277-
// +------[cond] |
278-
// | | |
279-
// | v 5 |
280-
// | [pat] |
281-
// | | |
282-
// | v 6 |
283-
// v 4 [body] -----+
284-
// [expr]
285-
//
286-
// Note that `break` and `continue` statements
287-
// may cause additional edges.
288-
289-
let head = self.expr(&**head, pred); // 1
290-
let loopback = self.add_dummy_node(&[head]); // 2
291-
let cond = self.add_dummy_node(&[loopback]); // 3
292-
let expr_exit = self.add_node(expr.id, &[cond]); // 4
293-
self.loop_scopes.push(LoopScope {
294-
loop_id: expr.id,
295-
continue_index: loopback,
296-
break_index: expr_exit,
297-
});
298-
let pat = self.pat(&**pat, cond); // 5
299-
let body = self.block(&**body, pat); // 6
300-
self.add_contained_edge(body, loopback); // 7
301-
self.loop_scopes.pop();
302-
expr_exit
267+
self.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
303268
}
304269

305270
ast::ExprLoop(ref body, _) => {

branches/tmp/src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -538,21 +538,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
538538
}
539539

540540
ast::ExprForLoop(ref pat, ref head, ref blk, _) => {
541-
// The pattern lives as long as the block.
542-
debug!("walk_expr for loop case: blk id={}", blk.id);
543-
self.consume_expr(&**head);
544-
545-
// Fetch the type of the value that the iteration yields to
546-
// produce the pattern's categorized mutable type.
547-
let pattern_type = return_if_err!(self.typer.node_ty(pat.id));
548-
let blk_scope = region::CodeExtent::from_node_id(blk.id);
549-
let pat_cmt = self.mc.cat_rvalue(pat.id,
550-
pat.span,
551-
ty::ReScope(blk_scope),
552-
pattern_type);
553-
self.walk_irrefutable_pat(pat_cmt, &**pat);
554-
555-
self.walk_block(&**blk);
541+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprForLoop");
556542
}
557543

558544
ast::ExprUnary(op, ref lhs) => {

branches/tmp/src/librustc/middle/liveness.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
491491
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
492492
}
493493
ast::ExprForLoop(ref pat, _, _, _) => {
494-
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
495-
debug!("adding local variable {} from for loop with bm {:?}",
496-
p_id, bm);
497-
let name = path1.node;
498-
ir.add_live_node_for_node(p_id, VarDefNode(sp));
499-
ir.add_variable(Local(LocalInfo {
500-
id: p_id,
501-
ident: name
502-
}));
503-
});
504-
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
505-
visit::walk_expr(ir, expr);
494+
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
506495
}
507496
ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op.node) => {
508497
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@@ -1035,8 +1024,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10351024
}
10361025

10371026
ast::ExprForLoop(ref pat, ref head, ref blk, _) => {
1038-
let ln = self.propagate_through_loop(expr, ForLoop(&**pat), &**blk, succ);
1039-
self.propagate_through_expr(&**head, ln)
1027+
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
10401028
}
10411029

10421030
// Note that labels have been resolved, so we don't need to look
@@ -1476,14 +1464,6 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14761464
visit::walk_expr(this, expr);
14771465
}
14781466

1479-
ast::ExprForLoop(ref pat, _, _, _) => {
1480-
this.pat_bindings(&**pat, |this, ln, var, sp, id| {
1481-
this.warn_about_unused(sp, id, ln, var);
1482-
});
1483-
1484-
visit::walk_expr(this, expr);
1485-
}
1486-
14871467
// no correctness conditions related to liveness
14881468
ast::ExprCall(..) | ast::ExprMethodCall(..) | ast::ExprIf(..) |
14891469
ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) |
@@ -1503,6 +1483,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
15031483
ast::ExprWhileLet(..) => {
15041484
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
15051485
}
1486+
ast::ExprForLoop(..) => {
1487+
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
1488+
}
15061489
}
15071490
}
15081491

branches/tmp/src/librustc/middle/mem_categorization.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
536536
ast::ExprBlock(..) | ast::ExprLoop(..) | ast::ExprMatch(..) |
537537
ast::ExprLit(..) | ast::ExprBreak(..) | ast::ExprMac(..) |
538538
ast::ExprAgain(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
539-
ast::ExprInlineAsm(..) | ast::ExprBox(..) |
540-
ast::ExprForLoop(..) => {
539+
ast::ExprInlineAsm(..) | ast::ExprBox(..) => {
541540
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
542541
}
543542

@@ -547,6 +546,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
547546
ast::ExprWhileLet(..) => {
548547
self.tcx().sess.span_bug(expr.span, "non-desugared ExprWhileLet");
549548
}
549+
ast::ExprForLoop(..) => {
550+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprForLoop");
551+
}
550552
}
551553
}
552554

branches/tmp/src/librustc/middle/ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,10 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
45824582
tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
45834583
}
45844584

4585+
ast::ExprForLoop(..) => {
4586+
tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
4587+
}
4588+
45854589
ast::ExprLit(ref lit) if lit_is_str(&**lit) => {
45864590
RvalueDpsExpr
45874591
}
@@ -4619,8 +4623,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
46194623
ast::ExprLoop(..) |
46204624
ast::ExprAssign(..) |
46214625
ast::ExprInlineAsm(..) |
4622-
ast::ExprAssignOp(..) |
4623-
ast::ExprForLoop(..) => {
4626+
ast::ExprAssignOp(..) => {
46244627
RvalueStmtExpr
46254628
}
46264629

branches/tmp/src/librustc_back/svh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ mod svh_visitor {
288288
ExprStruct(..) => SawExprStruct,
289289
ExprRepeat(..) => SawExprRepeat,
290290
ExprParen(..) => SawExprParen,
291-
ExprForLoop(..) => SawExprForLoop,
292291

293292
// just syntactic artifacts, expanded away by time of SVH.
293+
ExprForLoop(..) => unreachable!(),
294294
ExprIfLet(..) => unreachable!(),
295295
ExprWhileLet(..) => unreachable!(),
296296
ExprMac(..) => unreachable!(),

branches/tmp/src/librustc_trans/trans/debuginfo.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,24 +3627,9 @@ fn create_scope_map(cx: &CrateContext,
36273627
Found unexpanded while-let.");
36283628
}
36293629

3630-
ast::ExprForLoop(ref pattern, ref head, ref body, _) => {
3631-
walk_expr(cx, &**head, scope_stack, scope_map);
3632-
3633-
with_new_scope(cx,
3634-
exp.span,
3635-
scope_stack,
3636-
scope_map,
3637-
|cx, scope_stack, scope_map| {
3638-
scope_map.insert(exp.id,
3639-
scope_stack.last()
3640-
.unwrap()
3641-
.scope_metadata);
3642-
walk_pattern(cx,
3643-
&**pattern,
3644-
scope_stack,
3645-
scope_map);
3646-
walk_block(cx, &**body, scope_stack, scope_map);
3647-
})
3630+
ast::ExprForLoop(..) => {
3631+
cx.sess().span_bug(exp.span, "debuginfo::create_scope_map() - \
3632+
Found unexpanded for loop.");
36483633
}
36493634

36503635
ast::ExprMac(_) => {

branches/tmp/src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,22 +3762,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
37623762
ast::ExprWhileLet(..) => {
37633763
tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
37643764
}
3765-
ast::ExprForLoop(ref pat, ref head, ref block, _) => {
3766-
check_expr(fcx, &**head);
3767-
let typ = lookup_method_for_for_loop(fcx, &**head, expr.id);
3768-
vtable::select_new_fcx_obligations(fcx);
3769-
3770-
debug!("ExprForLoop each item has type {}",
3771-
fcx.infcx().resolve_type_vars_if_possible(&typ).repr(fcx.tcx()));
3772-
3773-
let pcx = pat_ctxt {
3774-
fcx: fcx,
3775-
map: pat_id_map(&tcx.def_map, &**pat),
3776-
};
3777-
_match::check_pat(&pcx, &**pat, typ);
3778-
3779-
check_block_no_value(fcx, &**block);
3780-
fcx.write_nil(id);
3765+
ast::ExprForLoop(..) => {
3766+
tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop");
37813767
}
37823768
ast::ExprLoop(ref body, _) => {
37833769
check_block_no_value(fcx, &**body);

branches/tmp/src/libsyntax/ext/expand.rs

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,101 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
225225
fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident))
226226
}
227227

228+
// Desugar ExprForLoop
229+
// From: `[opt_ident]: for <pat> in <head> <body>`
228230
ast::ExprForLoop(pat, head, body, opt_ident) => {
229-
let pat = fld.fold_pat(pat);
231+
// to:
232+
//
233+
// match ::std::iter::IntoIterator::into_iter(<head>) {
234+
// mut iter => {
235+
// [opt_ident]: loop {
236+
// match ::std::iter::Iterator::next(&mut iter) {
237+
// ::std::option::Option::Some(<pat>) => <body>,
238+
// ::std::option::Option::None => break
239+
// }
240+
// }
241+
// }
242+
// }
243+
244+
// expand <head>
230245
let head = fld.fold_expr(head);
231-
let (body, opt_ident) = expand_loop_block(body, opt_ident, fld);
232-
fld.cx.expr(span, ast::ExprForLoop(pat, head, body, opt_ident))
246+
247+
// create an hygienic ident
248+
let iter = {
249+
let ident = fld.cx.ident_of("iter");
250+
let new_ident = fresh_name(&ident);
251+
let rename = (ident, new_ident);
252+
let mut rename_list = vec![rename];
253+
let mut rename_fld = IdentRenamer{ renames: &mut rename_list };
254+
255+
rename_fld.fold_ident(ident)
256+
};
257+
258+
let pat_span = pat.span;
259+
// `:;std::option::Option::Some(<pat>) => <body>`
260+
let pat_arm = {
261+
let body_expr = fld.cx.expr_block(body);
262+
let some_pat = fld.cx.pat_some(pat_span, pat);
263+
264+
fld.cx.arm(pat_span, vec![some_pat], body_expr)
265+
};
266+
267+
// `::std::option::Option::None => break`
268+
let break_arm = {
269+
let break_expr = fld.cx.expr_break(span);
270+
271+
fld.cx.arm(span, vec![fld.cx.pat_none(span)], break_expr)
272+
};
273+
274+
// `match ::std::iter::Iterator::next(&mut iter) { ... }`
275+
let match_expr = {
276+
let next_path = {
277+
let strs = vec![
278+
fld.cx.ident_of("std"),
279+
fld.cx.ident_of("iter"),
280+
fld.cx.ident_of("Iterator"),
281+
fld.cx.ident_of("next"),
282+
];
283+
284+
fld.cx.path_global(span, strs)
285+
};
286+
let ref_mut_iter = fld.cx.expr_mut_addr_of(span, fld.cx.expr_ident(span, iter));
287+
let next_expr =
288+
fld.cx.expr_call(span, fld.cx.expr_path(next_path), vec![ref_mut_iter]);
289+
let arms = vec![pat_arm, break_arm];
290+
291+
// FIXME(japaric) This should use `ForLoopDesugar` as MatchSource
292+
fld.cx.expr_match(pat_span, next_expr, arms)
293+
};
294+
295+
// `[opt_ident]: loop { ... }`
296+
let loop_block = fld.cx.block_expr(match_expr);
297+
let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld);
298+
let loop_expr = fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident));
299+
300+
// `mut iter => { ... }`
301+
let iter_arm = {
302+
let iter_pat =
303+
fld.cx.pat_ident_binding_mode(span, iter, ast::BindByValue(ast::MutMutable));
304+
fld.cx.arm(span, vec![iter_pat], loop_expr)
305+
};
306+
307+
// `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
308+
let into_iter_expr = {
309+
let into_iter_path = {
310+
let strs = vec![
311+
fld.cx.ident_of("std"),
312+
fld.cx.ident_of("iter"),
313+
fld.cx.ident_of("IntoIterator"),
314+
fld.cx.ident_of("into_iter"),
315+
];
316+
317+
fld.cx.path_global(span, strs)
318+
};
319+
320+
fld.cx.expr_call(span, fld.cx.expr_path(into_iter_path), vec![head])
321+
};
322+
fld.cx.expr_match(span, into_iter_expr, vec![iter_arm])
233323
}
234324

235325
ast::ExprClosure(capture_clause, opt_kind, fn_decl, block) => {

0 commit comments

Comments
 (0)