Skip to content

Commit 90ef27d

Browse files
committed
---
yaml --- r: 10573 b: refs/heads/snap-stage3 c: 1ec5a5c h: refs/heads/master i: 10571: 74e08ce v: v3
1 parent ccf35ed commit 90ef27d

File tree

19 files changed

+92
-9
lines changed

19 files changed

+92
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ee9e5b9d201d876c07b00663e2df224eb170a0f2
4+
refs/heads/snap-stage3: 1ec5a5c635dba820246cbb4c7bea031b6add3b07
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/libsyntax/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ enum expr_ {
318318
// easily type this (a function returning nil on the inside but bool on
319319
// the outside).
320320
expr_loop_body(@expr),
321+
// Like expr_loop_body but for 'do' blocks
322+
expr_do_body(@expr),
321323
expr_block(blk),
322324

323325
/*

branches/snap-stage3/src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
415415
}
416416
expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
417417
expr_loop_body(f) { expr_loop_body(fld.fold_expr(f)) }
418+
expr_do_body(f) { expr_do_body(fld.fold_expr(f)) }
418419
expr_lit(_) { copy e }
419420
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
420421
expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) }

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ class parser {
772772
ret pexpr(self.parse_if_expr());
773773
} else if self.eat_keyword("for") {
774774
ret pexpr(self.parse_for_expr());
775+
} else if self.eat_keyword("do") {
776+
ret pexpr(self.parse_do_expr());
775777
} else if self.eat_keyword("while") {
776778
ret pexpr(self.parse_while_expr());
777779
} else if self.eat_keyword("loop") {
@@ -1312,6 +1314,23 @@ class parser {
13121314
}
13131315
}
13141316

1317+
fn parse_do_expr() -> @expr {
1318+
let lo = self.last_span;
1319+
let call = self.parse_expr_res(RESTRICT_STMT_EXPR);
1320+
alt call.node {
1321+
expr_call(f, args, true) {
1322+
let b_arg = vec::last(args);
1323+
let last = self.mk_expr(b_arg.span.lo, b_arg.span.hi,
1324+
expr_do_body(b_arg));
1325+
@{node: expr_call(f, vec::init(args) + [last], true)
1326+
with *call}
1327+
}
1328+
_ {
1329+
self.span_fatal(lo, "`do` must be followed by a block call");
1330+
}
1331+
}
1332+
}
1333+
13151334
fn parse_while_expr() -> @expr {
13161335
let lo = self.last_span.lo;
13171336
let cond = self.parse_expr();

branches/snap-stage3/src/libsyntax/parse/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn restricted_keyword_table() -> hashmap<str, ()> {
287287
"assert",
288288
"be", "break",
289289
"check", "claim", "class", "const", "cont", "copy", "crust",
290-
"drop",
290+
"do", "drop",
291291
"else", "enum", "export",
292292
"fail", "false", "fn", "for",
293293
"if", "iface", "impl", "import",

branches/snap-stage3/src/libsyntax/print/pprust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10481048
ast::expr_loop_body(body) {
10491049
print_expr(s, body);
10501050
}
1051+
ast::expr_do_body(body) {
1052+
print_expr(s, body);
1053+
}
10511054
ast::expr_block(blk) {
10521055
// containing cbox, will be closed by print-block at }
10531056
cbox(s, indent_unit);

branches/snap-stage3/src/libsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
382382
for args.each {|eo| visit_expr_opt(eo, e, v); }
383383
}
384384
expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
385-
expr_addr_of(_, x) | expr_unary(_, x) | expr_loop_body(x) |
385+
expr_addr_of(_, x) | expr_unary(_, x) |
386+
expr_loop_body(x) | expr_do_body(x) |
386387
expr_check(_, x) | expr_assert(x) {
387388
v.visit_expr(x, e, v);
388389
}

branches/snap-stage3/src/rustc/middle/borrowck/categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl public_methods for borrowck_ctxt {
174174
ast::expr_swap(*) | ast::expr_move(*) | ast::expr_assign(*) |
175175
ast::expr_assign_op(*) | ast::expr_fn(*) | ast::expr_fn_block(*) |
176176
ast::expr_assert(*) | ast::expr_check(*) | ast::expr_ret(*) |
177-
ast::expr_loop_body(*) | ast::expr_unary(*) |
177+
ast::expr_loop_body(*) | ast::expr_do_body(*) | ast::expr_unary(*) |
178178
ast::expr_copy(*) | ast::expr_cast(*) | ast::expr_fail(*) |
179179
ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) |
180180
ast::expr_if_check(*) | ast::expr_if(*) | ast::expr_log(*) |

branches/snap-stage3/src/rustc/middle/liveness.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) {
412412
expr_vec(*) | expr_rec(*) | expr_call(*) | expr_tup(*) |
413413
expr_bind(*) | expr_new(*) | expr_log(*) | expr_binary(*) |
414414
expr_assert(*) | expr_check(*) | expr_addr_of(*) | expr_copy(*) |
415-
expr_loop_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) |
415+
expr_loop_body(*) | expr_do_body(*) | expr_cast(*) |
416+
expr_unary(*) | expr_fail(*) |
416417
expr_break | expr_cont | expr_lit(_) | expr_ret(*) |
417418
expr_block(*) | expr_move(*) | expr_assign(*) | expr_swap(*) |
418419
expr_assign_op(*) | expr_mac(*) {
@@ -1054,6 +1055,7 @@ class liveness {
10541055
expr_addr_of(_, e) |
10551056
expr_copy(e) |
10561057
expr_loop_body(e) |
1058+
expr_do_body(e) |
10571059
expr_cast(e, _) |
10581060
expr_unary(_, e) {
10591061
self.propagate_through_expr(e, succ)
@@ -1406,7 +1408,8 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
14061408
expr_vec(*) | expr_rec(*) | expr_tup(*) |
14071409
expr_bind(*) | expr_new(*) | expr_log(*) | expr_binary(*) |
14081410
expr_assert(*) | expr_check(*) | expr_copy(*) |
1409-
expr_loop_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) |
1411+
expr_loop_body(*) | expr_do_body(*) |
1412+
expr_cast(*) | expr_unary(*) | expr_fail(*) |
14101413
expr_ret(*) | expr_break | expr_cont | expr_lit(_) |
14111414
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) {
14121415
visit::visit_expr(expr, self, vt);

branches/snap-stage3/src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,6 +3622,9 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
36223622
ast::expr_loop_body(blk) {
36233623
ret trans_loop_body(bcx, e, none, dest);
36243624
}
3625+
ast::expr_do_body(blk) {
3626+
ret trans_expr(bcx, blk, dest);
3627+
}
36253628
ast::expr_bind(f, args) {
36263629
ret closure::trans_bind(
36273630
bcx, f, args, e.id, dest);

branches/snap-stage3/src/rustc/middle/trans/type_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ fn mark_for_expr(cx: ctx, e: @expr) {
223223
expr_while(_, _) | expr_fail(_) | expr_break | expr_cont |
224224
expr_unary(_, _) | expr_lit(_) | expr_assert(_) | expr_check(_, _) |
225225
expr_if_check(_, _, _) | expr_mac(_) | expr_addr_of(_, _) |
226-
expr_ret(_) | expr_loop(_) | expr_bind(_, _) | expr_loop_body(_) {}
226+
expr_ret(_) | expr_loop(_) | expr_bind(_, _) |
227+
expr_loop_body(_) | expr_do_body(_) {}
227228
}
228229
}
229230

branches/snap-stage3/src/rustc/middle/tstate/pre_post_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
364364
} else { find_pre_post_exprs(fcx, [l, r], e.id); }
365365
}
366366
expr_addr_of(_, x) | expr_cast(x, _) | expr_unary(_, x) |
367-
expr_loop_body(x) | expr_assert(x) | expr_copy(x) {
367+
expr_loop_body(x) | expr_do_body(x) | expr_assert(x) | expr_copy(x) {
368368
find_pre_post_expr(fcx, x);
369369
copy_pre_post(fcx.ccx, e.id, x);
370370
}

branches/snap-stage3/src/rustc/middle/tstate/states.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
486486
}
487487
ret changed | set_poststate_ann(fcx.ccx, e.id, a_post);
488488
}
489-
expr_field(x, _, _) | expr_loop_body(x) | expr_unary(_, x) |
489+
expr_field(x, _, _) | expr_loop_body(x) | expr_do_body(x) |
490+
expr_unary(_, x) |
490491
expr_addr_of(_, x) | expr_assert(x) | expr_cast(x, _) |
491492
expr_copy(x) {
492493
ret find_pre_post_state_sub(fcx, pres, x, e.id, none);

branches/snap-stage3/src/rustc/middle/typeck/check.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,32 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
13641364
}
13651365
}
13661366
}
1367+
ast::expr_do_body(b) {
1368+
let expected_sty = unpack_expected(fcx, expected, {|x|some(x)}).get();
1369+
let (inner_ty, proto) = alt expected_sty {
1370+
ty::ty_fn(fty) {
1371+
(ty::mk_fn(tcx, fty), fty.proto)
1372+
}
1373+
_ {
1374+
tcx.sess.span_fatal(expr.span, "a do function's last argument \
1375+
should be of function type");
1376+
}
1377+
};
1378+
alt check b.node {
1379+
ast::expr_fn_block(decl, body, cap_clause) {
1380+
check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty));
1381+
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
1382+
capture::check_capture_clause(tcx, b.id, cap_clause);
1383+
}
1384+
}
1385+
let block_ty = structurally_resolved_type(
1386+
fcx, expr.span, fcx.node_ty(b.id));
1387+
alt check ty::get(block_ty).struct {
1388+
ty::ty_fn(fty) {
1389+
fcx.write_ty(expr.id, ty::mk_fn(tcx, fty));
1390+
}
1391+
}
1392+
}
13671393
ast::expr_block(b) {
13681394
// If this is an unchecked block, turn off purity-checking
13691395
bot = check_block(fcx, b);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let x = do y; //! ERROR: `do` must be followed by a block call
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(f: fn@(int) -> bool) -> bool { f(10) }
2+
3+
fn main() {
4+
assert do f() { |i| i == 10 } == 10; //! ERROR: expected `bool` but found `int`
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(f: fn@(int)) { f(10) }
2+
3+
fn main() {
4+
do f() { |i| assert i == 10 }
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(f: fn@(int) -> int) -> int { f(10) }
2+
3+
fn main() {
4+
assert do f() { |i| i } == 10;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(f: fn@(int) -> int) -> int { f(10) }
2+
3+
fn main() {
4+
assert do f { |i| i } == 10;
5+
}

0 commit comments

Comments
 (0)