Skip to content

Commit fd1029e

Browse files
msullivangraydon
authored andcommitted
Support move as an initializer.
1 parent 68b4688 commit fd1029e

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

src/comp/front/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ tag stmt_ {
208208
tag init_op {
209209
init_assign;
210210
init_recv;
211+
init_move;
211212
}
212213
213214
type initializer = rec(init_op op,

src/comp/front/parser.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,11 @@ fn parse_initializer(&parser p) -> option::t[ast::initializer] {
14491449
ret some(rec(op = ast::init_assign,
14501450
expr = parse_expr(p)));
14511451
}
1452+
case (token::LARROW) {
1453+
p.bump();
1454+
ret some(rec(op = ast::init_move,
1455+
expr = parse_expr(p)));
1456+
}
14521457
// Now that the the channel is the first argument to receive,
14531458
// combining it with an initializer doesn't really make sense.
14541459
// case (token::RECV) {

src/comp/middle/trans.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6375,6 +6375,11 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
63756375
auto sub = trans_expr(bcx, init.expr);
63766376
bcx = copy_val(sub.bcx, INIT, llptr, sub.val, ty).bcx;
63776377
}
6378+
case (ast::init_move) {
6379+
auto sub = trans_lval(bcx, init.expr);
6380+
bcx = move_val(sub.res.bcx, INIT, llptr,
6381+
sub.res.val, ty).bcx;
6382+
}
63786383
case (ast::init_recv) {
63796384
bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx;
63806385
}

src/comp/middle/typeck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,9 @@ fn check_decl_initializer(&@stmt_ctxt scx, &ast::def_id lid,
27232723
case (ast::init_assign) {
27242724
pushdown::pushdown_expr(scx, lty, init.expr);
27252725
}
2726+
case (ast::init_move) {
2727+
pushdown::pushdown_expr(scx, lty, init.expr);
2728+
}
27262729
case (ast::init_recv) {
27272730
auto port_ty = ty::mk_port(scx.fcx.ccx.tcx, lty);
27282731
pushdown::pushdown_expr(scx, port_ty, init.expr);

src/comp/pretty/pprust.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,12 @@ fn print_decl(&ps s, &@ast::decl decl) {
865865
case (ast::init_assign) {
866866
word_space(s, "=");
867867
}
868-
case (ast::init_recv) {
868+
case (ast::init_move) {
869869
word_space(s, "<-");
870870
}
871+
case (ast::init_recv) {
872+
word_space(s, "|>");
873+
}
871874
}
872875
print_expr(s, init.expr);
873876
}

0 commit comments

Comments
 (0)