diff --git a/doc/rust.md b/doc/rust.md index 074913c8bf1e6a86d9454e1eefe412b3da009199..f002393b71aced2ac46ef27fb2344fe2ed40d36d 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -209,9 +209,9 @@ import export use mod The keywords in [source files](#source-files) are the following strings: ~~~~~~~~ {.keyword} -alt assert +alt again assert break -check claim class const cont copy +check claim class const copy drop else enum export extern fail false fn for @@ -2034,19 +2034,19 @@ break_expr : "break" ; Executing a `break` expression immediately terminates the innermost loop enclosing it. It is only permitted in the body of a loop. -### Continue expressions +### Again expressions ~~~~~~~~{.ebnf .gram} -break_expr : "cont" ; +again_expr : "again" ; ~~~~~~~~ -Evaluating a `cont` expression immediately terminates the current iteration of +Evaluating an `again` expression immediately terminates the current iteration of the innermost loop enclosing it, returning control to the loop *head*. In the case of a `while` loop, the head is the conditional expression controlling the -loop. In the case of a `for` loop, the head is the vector-element increment -controlling the loop. +loop. In the case of a `for` loop, the head is the call-expression controlling +the loop. -A `cont` expression is only permitted in the body of a loop. +An `again` expression is only permitted in the body of a loop. ### For expressions diff --git a/doc/tutorial.md b/doc/tutorial.md index 0e54485bf17fbd7985a40341fa95f50f7c6ee86c..149afee960f0554852ae0e0ee5b66eabac120950 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -783,7 +783,7 @@ a specific value, are not allowed. `while` produces a loop that runs as long as its given condition (which must have type `bool`) evaluates to true. Inside a loop, the -keyword `break` can be used to abort the loop, and `cont` can be used +keyword `break` can be used to abort the loop, and `again` can be used to abort the current iteration and continue with the next. ~~~~ @@ -1187,7 +1187,7 @@ Empty argument lists can be omitted from `do` expressions. Most iteration in Rust is done with `for` loops. Like `do`, `for` is a nice syntax for doing control flow with closures. -Additionally, within a `for` loop, `break, `cont`, and `ret` +Additionally, within a `for` loop, `break, `again`, and `ret` work just as they do with `while` and `loop`. Consider again our `each` function, this time improved to @@ -1221,8 +1221,8 @@ each(~[2, 4, 8, 5, 16], |n| { With `for`, functions like `each` can be treated more like builtin looping structures. When calling `each` in a `for` loop, instead of returning `false` to break -out of the loop, you just write `break`. To continue -to the next iteration, write `cont`. +out of the loop, you just write `break`. To skip ahead +to the next iteration, write `again`. ~~~~ # import each = vec::each; diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 86e5f867cbaa380c9db329e1862c6e9ed5a9d641..a9691a836cb678f1be568c3f022870d80c72fcfd 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -56,9 +56,9 @@ "trait" "fn" "enum" "iface" "impl")) (puthash word 'def table)) - (dolist (word '("assert" + (dolist (word '("again" "assert" "break" - "check" "claim" "cont" "copy" + "check" "claim" "copy" "do" "drop" "else" "export" "extern" "fail" "for" diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index e6a7a9fcfe6f8113b9c83db6478cb4a197309ae6..4faf7a2f48d0c913f49c66b402b7c20d668f21e6 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -42,7 +42,7 @@ fn dsl(l: ast::lit_) -> ast::lit { } ~[dse(ast::expr_break), - dse(ast::expr_cont), + dse(ast::expr_again), dse(ast::expr_fail(option::none)), dse(ast::expr_fail(option::some( @dse(ast::expr_lit(@dsl(ast::lit_str(@"boo"))))))), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4c0be731df4ba960d5abf31de450e0aa9dda83d5..1941d809d7b8740a89c5f9bbcc384fb0aa5ef272 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -336,7 +336,7 @@ enum expr_ { expr_addr_of(mutability, @expr), expr_fail(option<@expr>), expr_break, - expr_cont, + expr_again, expr_ret(option<@expr>), expr_log(int, @expr, @expr), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 75977ba6169314282577d10420205ca6ac022633..7f83b16b8ab71600d5f07f978559c06a50cfbe95 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -464,7 +464,7 @@ fn fold_field_(field: field, fld: ast_fold) -> field { } expr_path(pth) { expr_path(fld.fold_path(pth)) } expr_fail(e) { expr_fail(option::map(e, fld.fold_expr)) } - expr_break | expr_cont { copy e } + expr_break | expr_again { copy e } expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) } expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv), fld.fold_expr(e)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2f4fe783b4903ca647c7ce7a985f47d7891a456a..3f430f8a98896a176ab337d73a5b1ad811d68a30 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -966,8 +966,9 @@ fn parse_bottom_expr() -> pexpr { } else if self.eat_keyword("break") { ex = expr_break; hi = self.span.hi; - } else if self.eat_keyword("cont") { - ex = expr_cont; + } else if self.eat_keyword("cont") || + self.eat_keyword("again") { + ex = expr_again; hi = self.span.hi; } else if self.eat_keyword("copy") { let e = self.parse_expr(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index dbc1e8b34e34df56586028e3c6b698f48b5699f8..b3fad7e9ffd940e00cabe94c66b685b65188d2ba 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -304,8 +304,7 @@ fn contextual_keyword_table() -> hashmap { fn restricted_keyword_table() -> hashmap { let words = str_hash(); let keys = ~[ - "alt", - "assert", + "alt", "again", "assert", "break", "check", "claim", "class", "const", "cont", "copy", "do", "drop", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5220ecdce936335870218211f506e18d1507e51e..f7acf9ea688039c267331823bf2c38a15ecf45c8 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1063,7 +1063,7 @@ fn print_field(s: ps, field: ast::field) { } } ast::expr_break { word(s.s, "break"); } - ast::expr_cont { word(s.s, "cont"); } + ast::expr_again { word(s.s, "again"); } ast::expr_ret(result) { word(s.s, "ret"); alt result { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ed54ad3308b0bc57148eaf9d734dc48c8ff2bc58..0a7e757bbba8989a1eb215ec1bbc0f89bbc17e8c 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -421,7 +421,7 @@ fn visit_expr(ex: @expr, e: E, v: vt) { expr_path(p) { visit_path(p, e, v); } expr_fail(eo) { visit_expr_opt(eo, e, v); } expr_break { } - expr_cont { } + expr_again { } expr_ret(eo) { visit_expr_opt(eo, e, v); } expr_log(_, lv, x) { v.visit_expr(lv, e, v); diff --git a/src/rustc/middle/borrowck/categorization.rs b/src/rustc/middle/borrowck/categorization.rs index deccf0af2b46d8e3273e643121519e6a887e55e9..1a2b4d7834eca382fdbd19a786354cdb89aaf11d 100644 --- a/src/rustc/middle/borrowck/categorization.rs +++ b/src/rustc/middle/borrowck/categorization.rs @@ -176,7 +176,7 @@ fn cat_expr(expr: @ast::expr) -> cmt { ast::expr_new(*) | ast::expr_binary(*) | ast::expr_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_again | ast::expr_rec(*) { ret self.cat_rvalue(expr, expr_ty); } } diff --git a/src/rustc/middle/check_loop.rs b/src/rustc/middle/check_loop.rs index 44fbdaef7ce40f82bf4756aae89c1124a69df1dc..e8e2c57a8b227bae4f85b0f19adfd1e04ba1a19f 100644 --- a/src/rustc/middle/check_loop.rs +++ b/src/rustc/middle/check_loop.rs @@ -33,7 +33,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) { tcx.sess.span_err(e.span, "`break` outside of loop"); } } - expr_cont { + expr_again { if !cx.in_loop { tcx.sess.span_err(e.span, "`cont` outside of loop"); } diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index 2f87f6d55de79324dddc7faa86321eb1d2f7ac71..50ab6b4b627bf80f288e6ef2c7bc5038e0757362 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -470,7 +470,7 @@ fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) { expr_assert(*) | expr_check(*) | expr_addr_of(*) | expr_copy(*) | expr_loop_body(*) | expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) | - expr_break | expr_cont | expr_lit(_) | expr_ret(*) | + expr_break | expr_again | expr_lit(_) | expr_ret(*) | expr_block(*) | expr_move(*) | expr_assign(*) | expr_swap(*) | expr_assign_op(*) | expr_mac(*) { visit::visit_expr(expr, self, vt); @@ -1009,7 +1009,7 @@ fn propagate_through_expr(expr: @expr, succ: live_node) -> live_node { self.break_ln } - expr_cont { + expr_again { if !self.cont_ln.is_valid() { self.tcx.sess.span_bug( expr.span, "cont with invalid cont_ln"); @@ -1457,7 +1457,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) { expr_assert(*) | expr_check(*) | expr_copy(*) | expr_loop_body(*) | expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) | - expr_ret(*) | expr_break | expr_cont | expr_lit(_) | + expr_ret(*) | expr_break | expr_again | expr_lit(_) | expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) { visit::visit_expr(expr, self, vt); } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 377dac6120fdee62fa05e7722dce025f874fc8db..459b14038450e2d6417f812e3bef48852e7ec3a8 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -3644,7 +3644,7 @@ fn unrooted(bcx: block, e: @ast::expr, dest: dest) -> block { assert dest == ignore; ret trans_break(bcx); } - ast::expr_cont { + ast::expr_again { assert dest == ignore; ret trans_cont(bcx); } diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index c8ff5ef4c16492d0d17de4b396fcabe4538a68a6..386bf06ef1434a441789636b6e1e32bdb7742596 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -242,7 +242,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { }) } expr_alt(_, _, _) | expr_block(_) | expr_if(_, _, _) | - expr_while(_, _) | expr_fail(_) | expr_break | expr_cont | + expr_while(_, _) | expr_fail(_) | expr_break | expr_again | expr_unary(_, _) | expr_lit(_) | expr_assert(_) | expr_check(_, _) | expr_if_check(_, _, _) | expr_mac(_) | expr_addr_of(_, _) | expr_ret(_) | expr_loop(_) | diff --git a/src/rustc/middle/tstate/pre_post_conditions.rs b/src/rustc/middle/tstate/pre_post_conditions.rs index 545f6ad6aa97c4096afe6eff98f805c00f10abde..c2c8810ec1bb19934233094e56d35b1998d041c8 100644 --- a/src/rustc/middle/tstate/pre_post_conditions.rs +++ b/src/rustc/middle/tstate/pre_post_conditions.rs @@ -446,7 +446,7 @@ fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, &&pp: pre_and_post, join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check); } expr_break { clear_pp(expr_pp(fcx.ccx, e)); } - expr_cont { clear_pp(expr_pp(fcx.ccx, e)); } + expr_again { clear_pp(expr_pp(fcx.ccx, e)); } expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); } } } diff --git a/src/rustc/middle/tstate/states.rs b/src/rustc/middle/tstate/states.rs index adf1efc85626f0981a0d558e6eb885c08b806504..f6cf240eeca3469b3c41a648d3223374ce402d71 100644 --- a/src/rustc/middle/tstate/states.rs +++ b/src/rustc/middle/tstate/states.rs @@ -498,7 +498,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool { ret join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check, pres); } expr_break { ret pure_exp(fcx.ccx, e.id, pres); } - expr_cont { ret pure_exp(fcx.ccx, e.id, pres); } + expr_again { ret pure_exp(fcx.ccx, e.id, pres); } } } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 647498a97e1d3d9caf40eddec3c7214453ff0346..a983240489ac87384e6ce4a451acc19ee198a456 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -1220,7 +1220,7 @@ fn check_expr_fn(fcx: @fn_ctxt, fcx.write_bot(id); } ast::expr_break { fcx.write_bot(id); bot = true; } - ast::expr_cont { fcx.write_bot(id); bot = true; } + ast::expr_again { fcx.write_bot(id); bot = true; } ast::expr_ret(expr_opt) { bot = true; let ret_ty = alt fcx.indirect_ret_ty { diff --git a/src/rustc/util/common.rs b/src/rustc/util/common.rs index 6a594879d1d41a47c9008ef6cc55b52428aac278..26b3077210511129cf21bb204ff6d02f19bf7d92 100644 --- a/src/rustc/util/common.rs +++ b/src/rustc/util/common.rs @@ -57,7 +57,7 @@ fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { fn has_nonlocal_exits(b: ast::blk) -> bool { do loop_query(b) |e| { alt e { - ast::expr_break | ast::expr_cont { true } + ast::expr_break | ast::expr_again { true } _ { false }}} }