Skip to content

Commit 13c924c

Browse files
committed
Remove do { ... } while ... from the language.
1 parent 5af58e7 commit 13c924c

File tree

16 files changed

+11
-118
lines changed

16 files changed

+11
-118
lines changed

src/fuzzer/fuzzer.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
7474
ast::expr_alt(_, _, _) { false }
7575
ast::expr_while(_, _) { false }
7676

77-
// https://github.com/mozilla/rust/issues/955
78-
ast::expr_do_while(_, _) { false }
79-
8077
// https://github.com/mozilla/rust/issues/929
8178
ast::expr_cast(_, _) { false }
8279
ast::expr_assert(_) { false }

src/librustsyntax/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ enum expr_ {
305305
expr_cast(@expr, @ty),
306306
expr_if(@expr, blk, option<@expr>),
307307
expr_while(@expr, blk),
308-
expr_do_while(blk, @expr),
309308
/* Conditionless loop (can be exited with break, cont, ret, or fail)
310309
Same semantics as while(true) { body }, but typestate knows that the
311310
(implicit) condition is always true. */

src/librustsyntax/fold.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
444444
expr_while(cond, body) {
445445
expr_while(fld.fold_expr(cond), fld.fold_block(body))
446446
}
447-
expr_do_while(blk, expr) {
448-
expr_do_while(fld.fold_block(blk), fld.fold_expr(expr))
449-
}
450447
expr_loop(body) {
451448
expr_loop(fld.fold_block(body))
452449
}

src/librustsyntax/parse/classify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
77
alt e.node {
88
ast::expr_if(_, _, _) | ast::expr_if_check(_, _, _)
99
| ast::expr_alt(_, _, _) | ast::expr_block(_)
10-
| ast::expr_do_while(_, _) | ast::expr_while(_, _)
11-
| ast::expr_loop(_) | ast::expr_call(_, _, true) {
10+
| ast::expr_while(_, _) | ast::expr_loop(_)
11+
| ast::expr_call(_, _, true) {
1212
false
1313
}
1414
_ { true }

src/librustsyntax/parse/parser.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
727727
ret pexpr(parse_for_expr(p));
728728
} else if eat_keyword(p, "while") {
729729
ret pexpr(parse_while_expr(p));
730-
} else if eat_keyword(p, "do") {
731-
ret pexpr(parse_do_while_expr(p));
732730
} else if eat_keyword(p, "loop") {
733731
ret pexpr(parse_loop_expr(p));
734732
} else if eat_keyword(p, "alt") {
@@ -1233,15 +1231,6 @@ fn parse_while_expr(p: parser) -> @expr {
12331231
ret mk_expr(p, lo, hi, expr_while(cond, body));
12341232
}
12351233

1236-
fn parse_do_while_expr(p: parser) -> @expr {
1237-
let lo = p.last_span.lo;
1238-
let body = parse_block_no_value(p);
1239-
expect_keyword(p, "while");
1240-
let cond = parse_expr(p);
1241-
let mut hi = cond.span.hi;
1242-
ret mk_expr(p, lo, hi, expr_do_while(body, cond));
1243-
}
1244-
12451234
fn parse_loop_expr(p: parser) -> @expr {
12461235
let lo = p.last_span.lo;
12471236
let body = parse_block_no_value(p);

src/librustsyntax/print/pprust.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -975,14 +975,6 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
975975
space(s.s);
976976
print_block(s, blk);
977977
}
978-
ast::expr_do_while(blk, expr) {
979-
head(s, "do");
980-
space(s.s);
981-
print_block(s, blk);
982-
space(s.s);
983-
word_space(s, "while");
984-
print_expr(s, expr);
985-
}
986978
ast::expr_alt(expr, arms, mode) {
987979
cbox(s, alt_indent_unit);
988980
ibox(s, 4u);

src/librustsyntax/visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
376376
}
377377
expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
378378
expr_loop(b) { v.visit_block(b, e, v); }
379-
expr_do_while(b, x) { v.visit_block(b, e, v); v.visit_expr(x, e, v); }
380379
expr_alt(x, arms, _) {
381380
v.visit_expr(x, e, v);
382381
for arms.each {|a| v.visit_arm(a, e, v); }

src/rustc/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
122122
check_lval(cx, dest, sc, v);
123123
}
124124
ast::expr_if(c, then, els) { check_if(c, then, els, sc, v); }
125-
ast::expr_while(_, _) | ast::expr_do_while(_, _) {
125+
ast::expr_while(_, _) {
126126
check_loop(*cx, sc) {|| visit::visit_expr(ex, sc, v); }
127127
}
128128
_ { handled = false; }

src/rustc/middle/borrowck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ impl categorize_methods for borrowck_ctxt {
761761
ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) |
762762
ast::expr_if_check(*) | ast::expr_if(*) | ast::expr_log(*) |
763763
ast::expr_new(*) | ast::expr_binary(*) | ast::expr_while(*) |
764-
ast::expr_do_while(*) | ast::expr_block(*) | ast::expr_loop(*) |
765-
ast::expr_alt(*) | ast::expr_lit(*) | ast::expr_break |
766-
ast::expr_mac(*) | ast::expr_cont | ast::expr_rec(*) {
764+
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) |
765+
ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) |
766+
ast::expr_cont | ast::expr_rec(*) {
767767
@{id:expr.id, span:expr.span,
768768
cat:cat_rvalue(rv_misc), lp:none,
769769
mutbl:m_imm, ty:expr_ty}

src/rustc/middle/check_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
1111
},
1212
visit_expr: {|e: @expr, cx: ctx, v: visit::vt<ctx>|
1313
alt e.node {
14-
expr_while(e, b) | expr_do_while(b, e) {
14+
expr_while(e, b) {
1515
v.visit_expr(e, cx, v);
1616
v.visit_block(b, {in_loop: true with cx}, v);
1717
}

src/rustc/middle/last_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
103103
leave_fn(cx);
104104
}
105105
expr_break { add_block_exit(cx, lp); }
106-
expr_while(_, _) | expr_do_while(_, _) | expr_loop(_) {
106+
expr_while(_, _) | expr_loop(_) {
107107
visit_block(lp, cx) {|| visit::visit_expr(ex, cx, v);}
108108
}
109109
expr_alt(input, arms, _) {

src/rustc/middle/trans/base.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,23 +1761,6 @@ fn trans_while(cx: block, cond: @ast::expr, body: ast::blk)
17611761
ret next_cx;
17621762
}
17631763

1764-
fn trans_do_while(cx: block, body: ast::blk, cond: @ast::expr) ->
1765-
block {
1766-
let _icx = cx.insn_ctxt("trans_do_while");
1767-
let next_cx = sub_block(cx, "next");
1768-
let body_cx =
1769-
loop_scope_block(cx, cont_self, next_cx,
1770-
"do-while loop body", body.span);
1771-
let body_end = trans_block(body_cx, body, ignore);
1772-
let cond_cx = scope_block(body_cx, "do-while cond");
1773-
cleanup_and_Br(body_end, body_cx, cond_cx.llbb);
1774-
let cond_res = trans_temp_expr(cond_cx, cond);
1775-
let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
1776-
CondBr(cond_bcx, cond_res.val, body_cx.llbb, next_cx.llbb);
1777-
Br(cx, body_cx.llbb);
1778-
ret next_cx;
1779-
}
1780-
17811764
fn trans_loop(cx:block, body: ast::blk) -> block {
17821765
let _icx = cx.insn_ctxt("trans_loop");
17831766
let next_cx = sub_block(cx, "next");
@@ -3285,10 +3268,6 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
32853268
assert dest == ignore;
32863269
ret trans_loop(bcx, body);
32873270
}
3288-
ast::expr_do_while(body, cond) {
3289-
assert dest == ignore;
3290-
ret trans_do_while(bcx, body, cond);
3291-
}
32923271
ast::expr_assign(dst, src) {
32933272
assert dest == ignore;
32943273
let src_r = trans_temp_lval(bcx, src);

src/rustc/middle/trans/type_use.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ fn mark_for_expr(cx: ctx, e: @expr) {
212212
}
213213
}
214214
}
215-
expr_do_while(_, _) | expr_alt(_, _, _) |
216-
expr_block(_) | expr_if(_, _, _) | expr_while(_, _) |
217-
expr_fail(_) | expr_break | expr_cont | expr_unary(_, _) |
218-
expr_lit(_) | expr_assert(_) | expr_check(_, _) |
215+
expr_alt(_, _, _) | expr_block(_) | expr_if(_, _, _) |
216+
expr_while(_, _) | expr_fail(_) | expr_break | expr_cont |
217+
expr_unary(_, _) | expr_lit(_) | expr_assert(_) | expr_check(_, _) |
219218
expr_if_check(_, _, _) | expr_mac(_) | expr_addr_of(_, _) |
220219
expr_ret(_) | expr_loop(_) | expr_bind(_, _) | expr_loop_body(_) {}
221220
}

src/rustc/middle/tstate/pre_post_conditions.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,25 +425,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
425425
intersect_states(expr_postcond(fcx.ccx, test),
426426
block_postcond(fcx.ccx, body)));
427427
}
428-
expr_do_while(body, test) {
429-
find_pre_post_block(fcx, body);
430-
find_pre_post_expr(fcx, test);
431-
let mut loop_postcond =
432-
seq_postconds(fcx,
433-
[block_postcond(fcx.ccx, body),
434-
expr_postcond(fcx.ccx, test)]);
435-
/* conservative approximation: if the body
436-
could break or cont, the test may never be executed */
437-
438-
if has_nonlocal_exits(body) {
439-
loop_postcond = empty_poststate(num_local_vars);
440-
}
441-
set_pre_and_post(fcx.ccx, e.id,
442-
seq_preconds(fcx,
443-
[block_pp(fcx.ccx, body),
444-
expr_pp(fcx.ccx, test)]),
445-
loop_postcond);
446-
}
447428
expr_loop(body) {
448429
find_pre_post_block(fcx, body);
449430
/* Infinite loop: if control passes it, everything is true. */

src/rustc/middle/tstate/states.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,40 +540,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
540540
intersect_states(e_post, b_post));
541541
}
542542
}
543-
expr_do_while(body, test) {
544-
let loop_pres = intersect_states(expr_poststate(fcx.ccx, test), pres);
545-
546-
let mut changed = set_prestate_ann(fcx.ccx, e.id, loop_pres);
547-
changed |= find_pre_post_state_block(fcx, loop_pres, body);
548-
/* conservative approximination: if the body of the loop
549-
could break or cont, we revert to the prestate
550-
(TODO: could treat cont differently from break, since
551-
if there's a cont, the test will execute) */
552-
553-
changed |=
554-
find_pre_post_state_expr(fcx, block_poststate(fcx.ccx, body),
555-
test);
556-
557-
let breaks = has_nonlocal_exits(body);
558-
if breaks {
559-
// this should probably be true_poststate and not pres,
560-
// b/c the body could invalidate stuff
561-
// FIXME [Break-unsound]
562-
// This is unsound as it is -- consider
563-
// while (true) {
564-
// x <- y;
565-
// break;
566-
// }
567-
// The poststate wouldn't take into account that
568-
// y gets deinitialized
569-
changed |= set_poststate_ann(fcx.ccx, e.id, pres);
570-
} else {
571-
changed |=
572-
set_poststate_ann(fcx.ccx, e.id,
573-
expr_poststate(fcx.ccx, test));
574-
}
575-
ret changed;
576-
}
577543
expr_loop(body) {
578544
let loop_pres =
579545
intersect_states(block_poststate(fcx.ccx, body), pres);

src/rustc/middle/typeck.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,11 +3444,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
34443444
check_block_no_value(fcx, body);
34453445
fcx.write_ty(id, ty::mk_nil(tcx));
34463446
}
3447-
ast::expr_do_while(body, cond) {
3448-
bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) |
3449-
check_block_no_value(fcx, body);
3450-
fcx.write_ty(id, fcx.node_ty(body.node.id));
3451-
}
34523447
ast::expr_loop(body) {
34533448
check_block_no_value(fcx, body);
34543449
fcx.write_ty(id, ty::mk_nil(tcx));

0 commit comments

Comments
 (0)