From 5af58e79269600c962f1de3bee57e804a36695a8 Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Tue, 8 May 2012 17:33:48 -0700 Subject: [PATCH 1/3] Removed all 4 uses of `do ... while` in the codebase. --- src/libcore/path.rs | 4 ++-- src/rustc/metadata/tydecode.rs | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 00a2397c000..75ca4cb035e 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -251,7 +251,7 @@ fn normalize(p: path) -> path { let mut t = []; let mut i = vec::len(s); let mut skip = 0; - do { + while i != 0u { i -= 1u; if s[i] == ".." { skip += 1; @@ -262,7 +262,7 @@ fn normalize(p: path) -> path { skip -= 1; } } - } while i != 0u; + } let mut t = vec::reversed(t); while skip > 0 { t += [".."]; diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index 644a38b8c8d..dbdb8137b8a 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -69,10 +69,11 @@ fn parse_constrs(st: @pstate, conv: conv_did) -> [@ty::constr] { let mut rslt: [@ty::constr] = []; alt peek(st) { ':' { - do { + loop { next(st); rslt += [parse_constr(st, conv, parse_constr_arg)]; - } while peek(st) == ';' + if peek(st) != ';' { break; } + } } _ { } } @@ -84,10 +85,11 @@ fn parse_ty_constrs(st: @pstate, conv: conv_did) -> [@ty::type_constr] { let mut rslt: [@ty::type_constr] = []; alt peek(st) { ':' { - do { + loop { next(st); rslt += [parse_constr(st, conv, parse_ty_constr_arg)]; - } while peek(st) == ';' + if peek(st) != ';' { break; } + } } _ { } } @@ -154,12 +156,13 @@ fn parse_constr(st: @pstate, conv: conv_did, assert (ignore == '('); let def = parse_def(st, conv); let mut an_arg: constr_arg_general_; - do { + loop { an_arg = pser(st); // FIXME use a real span args += [@respan(sp, an_arg)]; ignore = next(st); - } while ignore == ';' + if ignore != ';' { break; } + } assert (ignore == ')'); ret @respan(sp, {path: pth, args: args, id: def}); } From 13c924c049465f91dda8b7cee416d1fceaf4a596 Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Wed, 9 May 2012 09:17:27 -0700 Subject: [PATCH 2/3] Remove `do { ... } while ...` from the language. --- src/fuzzer/fuzzer.rs | 3 -- src/librustsyntax/ast.rs | 1 - src/librustsyntax/fold.rs | 3 -- src/librustsyntax/parse/classify.rs | 4 +-- src/librustsyntax/parse/parser.rs | 11 ------ src/librustsyntax/print/pprust.rs | 8 ----- src/librustsyntax/visit.rs | 1 - src/rustc/middle/alias.rs | 2 +- src/rustc/middle/borrowck.rs | 6 ++-- src/rustc/middle/check_loop.rs | 2 +- src/rustc/middle/last_use.rs | 2 +- src/rustc/middle/trans/base.rs | 21 ------------ src/rustc/middle/trans/type_use.rs | 7 ++-- .../middle/tstate/pre_post_conditions.rs | 19 ----------- src/rustc/middle/tstate/states.rs | 34 ------------------- src/rustc/middle/typeck.rs | 5 --- 16 files changed, 11 insertions(+), 118 deletions(-) diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 594748e2eb9..dd65b0142ea 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -74,9 +74,6 @@ pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool { ast::expr_alt(_, _, _) { false } ast::expr_while(_, _) { false } - // https://github.com/mozilla/rust/issues/955 - ast::expr_do_while(_, _) { false } - // https://github.com/mozilla/rust/issues/929 ast::expr_cast(_, _) { false } ast::expr_assert(_) { false } diff --git a/src/librustsyntax/ast.rs b/src/librustsyntax/ast.rs index 210244eca91..fb97751fd51 100644 --- a/src/librustsyntax/ast.rs +++ b/src/librustsyntax/ast.rs @@ -305,7 +305,6 @@ enum expr_ { expr_cast(@expr, @ty), expr_if(@expr, blk, option<@expr>), expr_while(@expr, blk), - expr_do_while(blk, @expr), /* Conditionless loop (can be exited with break, cont, ret, or fail) Same semantics as while(true) { body }, but typestate knows that the (implicit) condition is always true. */ diff --git a/src/librustsyntax/fold.rs b/src/librustsyntax/fold.rs index ebc65c9db38..7e5a315a1e1 100644 --- a/src/librustsyntax/fold.rs +++ b/src/librustsyntax/fold.rs @@ -444,9 +444,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { expr_while(cond, body) { expr_while(fld.fold_expr(cond), fld.fold_block(body)) } - expr_do_while(blk, expr) { - expr_do_while(fld.fold_block(blk), fld.fold_expr(expr)) - } expr_loop(body) { expr_loop(fld.fold_block(body)) } diff --git a/src/librustsyntax/parse/classify.rs b/src/librustsyntax/parse/classify.rs index 99a6462bfca..70f89a38f47 100644 --- a/src/librustsyntax/parse/classify.rs +++ b/src/librustsyntax/parse/classify.rs @@ -7,8 +7,8 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { alt e.node { ast::expr_if(_, _, _) | ast::expr_if_check(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_) - | ast::expr_do_while(_, _) | ast::expr_while(_, _) - | ast::expr_loop(_) | ast::expr_call(_, _, true) { + | ast::expr_while(_, _) | ast::expr_loop(_) + | ast::expr_call(_, _, true) { false } _ { true } diff --git a/src/librustsyntax/parse/parser.rs b/src/librustsyntax/parse/parser.rs index 7b1b9823a1f..125dbb927f4 100644 --- a/src/librustsyntax/parse/parser.rs +++ b/src/librustsyntax/parse/parser.rs @@ -727,8 +727,6 @@ fn parse_bottom_expr(p: parser) -> pexpr { ret pexpr(parse_for_expr(p)); } else if eat_keyword(p, "while") { ret pexpr(parse_while_expr(p)); - } else if eat_keyword(p, "do") { - ret pexpr(parse_do_while_expr(p)); } else if eat_keyword(p, "loop") { ret pexpr(parse_loop_expr(p)); } else if eat_keyword(p, "alt") { @@ -1233,15 +1231,6 @@ fn parse_while_expr(p: parser) -> @expr { ret mk_expr(p, lo, hi, expr_while(cond, body)); } -fn parse_do_while_expr(p: parser) -> @expr { - let lo = p.last_span.lo; - let body = parse_block_no_value(p); - expect_keyword(p, "while"); - let cond = parse_expr(p); - let mut hi = cond.span.hi; - ret mk_expr(p, lo, hi, expr_do_while(body, cond)); -} - fn parse_loop_expr(p: parser) -> @expr { let lo = p.last_span.lo; let body = parse_block_no_value(p); diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs index 9af860e8872..46745b7e28c 100644 --- a/src/librustsyntax/print/pprust.rs +++ b/src/librustsyntax/print/pprust.rs @@ -975,14 +975,6 @@ fn print_expr(s: ps, &&expr: @ast::expr) { space(s.s); print_block(s, blk); } - ast::expr_do_while(blk, expr) { - head(s, "do"); - space(s.s); - print_block(s, blk); - space(s.s); - word_space(s, "while"); - print_expr(s, expr); - } ast::expr_alt(expr, arms, mode) { cbox(s, alt_indent_unit); ibox(s, 4u); diff --git a/src/librustsyntax/visit.rs b/src/librustsyntax/visit.rs index 2468ab68aa3..c9c751900c8 100644 --- a/src/librustsyntax/visit.rs +++ b/src/librustsyntax/visit.rs @@ -376,7 +376,6 @@ fn visit_expr(ex: @expr, e: E, v: vt) { } expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); } expr_loop(b) { v.visit_block(b, e, v); } - expr_do_while(b, x) { v.visit_block(b, e, v); v.visit_expr(x, e, v); } expr_alt(x, arms, _) { v.visit_expr(x, e, v); for arms.each {|a| v.visit_arm(a, e, v); } diff --git a/src/rustc/middle/alias.rs b/src/rustc/middle/alias.rs index 444947c471b..f3b6cbf6efc 100644 --- a/src/rustc/middle/alias.rs +++ b/src/rustc/middle/alias.rs @@ -122,7 +122,7 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt) { check_lval(cx, dest, sc, v); } ast::expr_if(c, then, els) { check_if(c, then, els, sc, v); } - ast::expr_while(_, _) | ast::expr_do_while(_, _) { + ast::expr_while(_, _) { check_loop(*cx, sc) {|| visit::visit_expr(ex, sc, v); } } _ { handled = false; } diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs index 021f0cd4b77..9e87cbc0bcd 100644 --- a/src/rustc/middle/borrowck.rs +++ b/src/rustc/middle/borrowck.rs @@ -761,9 +761,9 @@ impl categorize_methods for borrowck_ctxt { ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) | ast::expr_if_check(*) | ast::expr_if(*) | ast::expr_log(*) | ast::expr_new(*) | ast::expr_binary(*) | ast::expr_while(*) | - ast::expr_do_while(*) | ast::expr_block(*) | ast::expr_loop(*) | - ast::expr_alt(*) | ast::expr_lit(*) | ast::expr_break | - ast::expr_mac(*) | ast::expr_cont | ast::expr_rec(*) { + ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) | + ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) | + ast::expr_cont | ast::expr_rec(*) { @{id:expr.id, span:expr.span, cat:cat_rvalue(rv_misc), lp:none, mutbl:m_imm, ty:expr_ty} diff --git a/src/rustc/middle/check_loop.rs b/src/rustc/middle/check_loop.rs index 99dadb5922a..b815afd3646 100644 --- a/src/rustc/middle/check_loop.rs +++ b/src/rustc/middle/check_loop.rs @@ -11,7 +11,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) { }, visit_expr: {|e: @expr, cx: ctx, v: visit::vt| alt e.node { - expr_while(e, b) | expr_do_while(b, e) { + expr_while(e, b) { v.visit_expr(e, cx, v); v.visit_block(b, {in_loop: true with cx}, v); } diff --git a/src/rustc/middle/last_use.rs b/src/rustc/middle/last_use.rs index df24a98c923..4454c76d656 100644 --- a/src/rustc/middle/last_use.rs +++ b/src/rustc/middle/last_use.rs @@ -103,7 +103,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt) { leave_fn(cx); } expr_break { add_block_exit(cx, lp); } - expr_while(_, _) | expr_do_while(_, _) | expr_loop(_) { + expr_while(_, _) | expr_loop(_) { visit_block(lp, cx) {|| visit::visit_expr(ex, cx, v);} } expr_alt(input, arms, _) { diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index f79cba16510..1df25c9e93e 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1761,23 +1761,6 @@ fn trans_while(cx: block, cond: @ast::expr, body: ast::blk) ret next_cx; } -fn trans_do_while(cx: block, body: ast::blk, cond: @ast::expr) -> - block { - let _icx = cx.insn_ctxt("trans_do_while"); - let next_cx = sub_block(cx, "next"); - let body_cx = - loop_scope_block(cx, cont_self, next_cx, - "do-while loop body", body.span); - let body_end = trans_block(body_cx, body, ignore); - let cond_cx = scope_block(body_cx, "do-while cond"); - cleanup_and_Br(body_end, body_cx, cond_cx.llbb); - let cond_res = trans_temp_expr(cond_cx, cond); - let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx); - CondBr(cond_bcx, cond_res.val, body_cx.llbb, next_cx.llbb); - Br(cx, body_cx.llbb); - ret next_cx; -} - fn trans_loop(cx:block, body: ast::blk) -> block { let _icx = cx.insn_ctxt("trans_loop"); let next_cx = sub_block(cx, "next"); @@ -3285,10 +3268,6 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block { assert dest == ignore; ret trans_loop(bcx, body); } - ast::expr_do_while(body, cond) { - assert dest == ignore; - ret trans_do_while(bcx, body, cond); - } ast::expr_assign(dst, src) { assert dest == ignore; let src_r = trans_temp_lval(bcx, src); diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index 3ec11d5b0c4..4b57f33af7d 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -212,10 +212,9 @@ fn mark_for_expr(cx: ctx, e: @expr) { } } } - expr_do_while(_, _) | expr_alt(_, _, _) | - expr_block(_) | expr_if(_, _, _) | expr_while(_, _) | - expr_fail(_) | expr_break | expr_cont | expr_unary(_, _) | - expr_lit(_) | expr_assert(_) | expr_check(_, _) | + expr_alt(_, _, _) | expr_block(_) | expr_if(_, _, _) | + expr_while(_, _) | expr_fail(_) | expr_break | expr_cont | + expr_unary(_, _) | expr_lit(_) | expr_assert(_) | expr_check(_, _) | expr_if_check(_, _, _) | expr_mac(_) | expr_addr_of(_, _) | expr_ret(_) | expr_loop(_) | expr_bind(_, _) | expr_loop_body(_) {} } diff --git a/src/rustc/middle/tstate/pre_post_conditions.rs b/src/rustc/middle/tstate/pre_post_conditions.rs index 415dda8992a..559e8587cef 100644 --- a/src/rustc/middle/tstate/pre_post_conditions.rs +++ b/src/rustc/middle/tstate/pre_post_conditions.rs @@ -425,25 +425,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) { intersect_states(expr_postcond(fcx.ccx, test), block_postcond(fcx.ccx, body))); } - expr_do_while(body, test) { - find_pre_post_block(fcx, body); - find_pre_post_expr(fcx, test); - let mut loop_postcond = - seq_postconds(fcx, - [block_postcond(fcx.ccx, body), - expr_postcond(fcx.ccx, test)]); - /* conservative approximation: if the body - could break or cont, the test may never be executed */ - - if has_nonlocal_exits(body) { - loop_postcond = empty_poststate(num_local_vars); - } - set_pre_and_post(fcx.ccx, e.id, - seq_preconds(fcx, - [block_pp(fcx.ccx, body), - expr_pp(fcx.ccx, test)]), - loop_postcond); - } expr_loop(body) { find_pre_post_block(fcx, body); /* Infinite loop: if control passes it, everything is true. */ diff --git a/src/rustc/middle/tstate/states.rs b/src/rustc/middle/tstate/states.rs index 58dd1031faa..8fbdec3d9b5 100644 --- a/src/rustc/middle/tstate/states.rs +++ b/src/rustc/middle/tstate/states.rs @@ -540,40 +540,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool { intersect_states(e_post, b_post)); } } - expr_do_while(body, test) { - let loop_pres = intersect_states(expr_poststate(fcx.ccx, test), pres); - - let mut changed = set_prestate_ann(fcx.ccx, e.id, loop_pres); - changed |= find_pre_post_state_block(fcx, loop_pres, body); - /* conservative approximination: if the body of the loop - could break or cont, we revert to the prestate - (TODO: could treat cont differently from break, since - if there's a cont, the test will execute) */ - - changed |= - find_pre_post_state_expr(fcx, block_poststate(fcx.ccx, body), - test); - - let breaks = has_nonlocal_exits(body); - if breaks { - // this should probably be true_poststate and not pres, - // b/c the body could invalidate stuff - // FIXME [Break-unsound] - // This is unsound as it is -- consider - // while (true) { - // x <- y; - // break; - // } - // The poststate wouldn't take into account that - // y gets deinitialized - changed |= set_poststate_ann(fcx.ccx, e.id, pres); - } else { - changed |= - set_poststate_ann(fcx.ccx, e.id, - expr_poststate(fcx.ccx, test)); - } - ret changed; - } expr_loop(body) { let loop_pres = intersect_states(block_poststate(fcx.ccx, body), pres); diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 584a45bc6b7..472a4f43e2c 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -3444,11 +3444,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); } - ast::expr_do_while(body, cond) { - bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) | - check_block_no_value(fcx, body); - fcx.write_ty(id, fcx.node_ty(body.node.id)); - } ast::expr_loop(body) { check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); From f943667af391f7003a46aa5c3fc1a5ac0360574a Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Thu, 10 May 2012 14:06:19 -0700 Subject: [PATCH 3/3] Remove `do ... while` loops from the tests and docs. --- doc/rust.md | 33 ++++--------------- doc/tutorial.md | 26 +++++++-------- src/test/compile-fail/borrowck-lend-flow.rs | 18 ---------- src/test/compile-fail/break-uninit.rs | 2 +- src/test/compile-fail/break-uninit2.rs | 2 +- ...onstraints.rs => loop-pred-constraints.rs} | 7 ++-- ...le-constraints.rs => while-constraints.rs} | 2 +- src/test/run-fail/do-while-body-fails.rs | 2 -- src/test/run-fail/do-while-fail.rs | 4 --- src/test/run-fail/while-body-fails.rs | 2 ++ src/test/run-fail/while-fail.rs | 4 +++ src/test/run-pass/break.rs | 7 ++-- src/test/run-pass/issue-1257.rs | 4 +-- src/test/run-pass/weird-exprs.rs | 7 ++-- .../{while-and-do-while.rs => while.rs} | 4 +-- 15 files changed, 45 insertions(+), 79 deletions(-) rename src/test/compile-fail/{do-while-pred-constraints.rs => loop-pred-constraints.rs} (67%) rename src/test/compile-fail/{do-while-constraints.rs => while-constraints.rs} (69%) delete mode 100644 src/test/run-fail/do-while-body-fails.rs delete mode 100644 src/test/run-fail/do-while-fail.rs create mode 100644 src/test/run-fail/while-body-fails.rs create mode 100644 src/test/run-fail/while-fail.rs rename src/test/run-pass/{while-and-do-while.rs => while.rs} (87%) diff --git a/doc/rust.md b/doc/rust.md index 4bf45788c47..d7e35d8339f 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1991,28 +1991,19 @@ way. *TODO*. -### While expressions +### While loops ~~~~~~~~{.ebnf .gram} while_expr : "while" expr '{' block '}' | "do" '{' block '}' "while" expr ; ~~~~~~~~ -A `while` expression is a loop construct. A `while` loop may be either a -simple `while` or a `do`-`while` loop. +A `while` loop begins by evaluating the boolean loop conditional expression. +If the loop conditional expression evaluates to `true`, the loop body block +executes and control returns to the loop conditional expression. If the loop +conditional expression evaluates to `false`, the `while` expression completes. -In the case of a simple `while`, the loop begins by evaluating the boolean -loop conditional expression. If the loop conditional expression evaluates to -`true`, the loop body block executes and control returns to the loop -conditional expression. If the loop conditional expression evaluates to -`false`, the `while` expression completes. - -In the case of a `do`-`while`, the loop begins with an execution of the loop -body. After the loop body executes, it evaluates the loop conditional -expression. If it evaluates to `true`, control returns to the beginning of the -loop body. If it evaluates to `false`, control exits the loop. - -An example of a simple `while` expression: +An example: ~~~~ # let mut i = 0; @@ -2024,18 +2015,6 @@ while i < 10 { } ~~~~ -An example of a `do`-`while` expression: - -~~~~ -# let mut i = 0; -# let println = io::println; - -do { - println("hello\n"); - i = i + 1; -} while i < 10; -~~~~ - ### Infinite loops A `loop` expression denotes an infinite loop: diff --git a/doc/tutorial.md b/doc/tutorial.md index 54be869f00d..8f1affc1284 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -667,6 +667,15 @@ a specific value, are not allowed. keyword `break` can be used to abort the loop, and `cont` can be used to abort the current iteration and continue with the next. +~~~~ +let mut cake_amount = 8; +while cake_amount > 0 { + cake_amount -= 1; +} +~~~~ + +`loop` is the preferred way of writing `while true`: + ~~~~ let mut x = 5; while true { @@ -679,17 +688,6 @@ while true { This code prints out a weird sequence of numbers and stops as soon as it finds one that can be divided by five. -There's also `while`'s ugly cousin, `do`/`while`, which does not check -its condition on the first iteration, using traditional syntax: - -~~~~ -# fn eat_cake() {} -# fn any_cake_left() -> bool { false } -do { - eat_cake(); -} while any_cake_left(); -~~~~ - For more involved iteration, such as going over the elements of a collection, Rust uses higher-order functions. We'll come back to those in a moment. @@ -2496,12 +2494,12 @@ Here is the function which implements the child task: fn stringifier(from_parent: comm::port, to_parent: comm::chan) { let mut value: uint; - do { + loop { value = comm::recv(from_parent); comm::send(to_parent, uint::to_str(value, 10u)); - } while value != 0u; + if value == 0u { break; } + } } - ~~~~ You can see that the function takes two parameters. The first is a diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index afe23a40a5d..0aec0cc86bf 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -61,24 +61,6 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) { } } -fn do_while_aliased_mut(cond: bool) { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - do { - borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //! NOTE prior loan as mutable granted here - } while cond; -} - -fn loop_in_block() { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - uint::range(0u, 10u) {|_i| - borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //! NOTE prior loan as mutable granted here - } -} - fn at_most_once_block() { fn at_most_once(f: fn()) { f() } diff --git a/src/test/compile-fail/break-uninit.rs b/src/test/compile-fail/break-uninit.rs index 294b5133725..8babc95f0dc 100644 --- a/src/test/compile-fail/break-uninit.rs +++ b/src/test/compile-fail/break-uninit.rs @@ -4,7 +4,7 @@ fn foo() -> int { let x: int; let i: int; - do { i = 0; break; x = 0; } while x != 0 + loop { i = 0; break; x = 0; } log(debug, x); diff --git a/src/test/compile-fail/break-uninit2.rs b/src/test/compile-fail/break-uninit2.rs index 8c882fa0c84..1229e0dc0ee 100644 --- a/src/test/compile-fail/break-uninit2.rs +++ b/src/test/compile-fail/break-uninit2.rs @@ -4,7 +4,7 @@ fn foo() -> int { let x: int; let i: int; - do { i = 0; break; x = 0; } while 1 != 2 + while 1 != 2 { i = 0; break; x = 0; } log(debug, x); diff --git a/src/test/compile-fail/do-while-pred-constraints.rs b/src/test/compile-fail/loop-pred-constraints.rs similarity index 67% rename from src/test/compile-fail/do-while-pred-constraints.rs rename to src/test/compile-fail/loop-pred-constraints.rs index 03d00dd02e8..b085de80a23 100644 --- a/src/test/compile-fail/do-while-pred-constraints.rs +++ b/src/test/compile-fail/loop-pred-constraints.rs @@ -1,14 +1,17 @@ +// xfail-test +// https://github.com/mozilla/rust/issues/2374 // error-pattern:unsatisfied precondition constraint (for example, even(y + fn print_even(y: int) : even(y) { log(debug, y); } pure fn even(y: int) -> bool { true } fn main() { - let y: int = 42; + let mut y = 42; check (even(y)); loop { print_even(y); - do { do { do { y += 1; } while false } while false } while false + loop { y += 1; break; } } } diff --git a/src/test/compile-fail/do-while-constraints.rs b/src/test/compile-fail/while-constraints.rs similarity index 69% rename from src/test/compile-fail/do-while-constraints.rs rename to src/test/compile-fail/while-constraints.rs index a9153338123..ca8d0140108 100644 --- a/src/test/compile-fail/do-while-constraints.rs +++ b/src/test/compile-fail/while-constraints.rs @@ -5,6 +5,6 @@ fn main() { let x: int; loop { log(debug, y); - do { do { do { x <- y; } while true } while true } while true + while true { while true { while true { x <- y; } } } } } diff --git a/src/test/run-fail/do-while-body-fails.rs b/src/test/run-fail/do-while-body-fails.rs deleted file mode 100644 index 08835ab9204..00000000000 --- a/src/test/run-fail/do-while-body-fails.rs +++ /dev/null @@ -1,2 +0,0 @@ -// error-pattern:quux -fn main() { let x: int = do { fail "quux"; } while true; } diff --git a/src/test/run-fail/do-while-fail.rs b/src/test/run-fail/do-while-fail.rs deleted file mode 100644 index 38c6d38f309..00000000000 --- a/src/test/run-fail/do-while-fail.rs +++ /dev/null @@ -1,4 +0,0 @@ -// error-pattern:giraffe -fn main() { - fail do { fail "giraffe" } while true; -} diff --git a/src/test/run-fail/while-body-fails.rs b/src/test/run-fail/while-body-fails.rs new file mode 100644 index 00000000000..da241afe8a3 --- /dev/null +++ b/src/test/run-fail/while-body-fails.rs @@ -0,0 +1,2 @@ +// error-pattern:quux +fn main() { let x: int = { while true { fail "quux"; } ; 8 } ; } diff --git a/src/test/run-fail/while-fail.rs b/src/test/run-fail/while-fail.rs new file mode 100644 index 00000000000..3f1f9f3e655 --- /dev/null +++ b/src/test/run-fail/while-fail.rs @@ -0,0 +1,4 @@ +// error-pattern:giraffe +fn main() { + fail { while true { fail "giraffe"}; "clandestine" }; +} diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 9f0d1028e6a..4770b9ce886 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -4,7 +4,7 @@ fn main() { let mut i = 0; while i < 20 { i += 1; if i == 10 { break; } } assert (i == 10); - do { i += 1; if i == 20 { break; } } while i < 30 + loop { i += 1; if i == 20 { break; } } assert (i == 20); for vec::each([1, 2, 3, 4, 5, 6]) {|x| if x == 3 { break; } assert (x <= 3); @@ -12,7 +12,10 @@ fn main() { i = 0; while i < 10 { i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0); } i = 0; - do { i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0); } while i < 10 + loop { + i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0); + if i >= 10 { break; } + } for vec::each([1, 2, 3, 4, 5, 6]) {|x| if x % 2 == 0 { cont; } assert (x % 2 != 0); diff --git a/src/test/run-pass/issue-1257.rs b/src/test/run-pass/issue-1257.rs index 7ae714ac060..870d4aec403 100644 --- a/src/test/run-pass/issue-1257.rs +++ b/src/test/run-pass/issue-1257.rs @@ -1,8 +1,8 @@ fn main () { let mut line = ""; let mut i = 0; - do { + while line != "exit" { line = if i == 9 { "exit" } else { "notexit" }; i += 1; - } while line != "exit"; + } } diff --git a/src/test/run-pass/weird-exprs.rs b/src/test/run-pass/weird-exprs.rs index bf3bd4c8ae6..0b4e90ae1df 100644 --- a/src/test/run-pass/weird-exprs.rs +++ b/src/test/run-pass/weird-exprs.rs @@ -16,7 +16,7 @@ fn what() { } fn zombiejesus() { - do { + loop { while (ret) { if (ret) { alt (ret) { @@ -33,7 +33,8 @@ fn zombiejesus() { ret; } } - } while ret + if (ret) { break; } + } } fn notsure() { @@ -58,7 +59,7 @@ fn canttouchthis() -> uint { fn angrydome() { loop { if break { } } let mut i = 0; - do { i += 1; if i == 1 { alt check cont { 1 { } } } } while false + loop { i += 1; if i == 1 { alt check cont { 1 { } } } break; } } fn evil_lincoln() { let evil <- #debug("lincoln"); } diff --git a/src/test/run-pass/while-and-do-while.rs b/src/test/run-pass/while.rs similarity index 87% rename from src/test/run-pass/while-and-do-while.rs rename to src/test/run-pass/while.rs index c0dacbaf549..4fce93acd35 100644 --- a/src/test/run-pass/while-and-do-while.rs +++ b/src/test/run-pass/while.rs @@ -4,9 +4,9 @@ fn main() { let mut x: int = 10; let mut y: int = 0; while y < x { log(debug, y); #debug("hello"); y = y + 1; } - do { + while x > 0 { #debug("goodbye"); x = x - 1; log(debug, x); - } while x > 0 + } }