Support move as an initializer.
This commit is contained in:
parent
68b4688875
commit
fd1029e6dd
@ -208,6 +208,7 @@ fn unop_to_str(unop op) -> str {
|
||||
tag init_op {
|
||||
init_assign;
|
||||
init_recv;
|
||||
init_move;
|
||||
}
|
||||
|
||||
type initializer = rec(init_op op,
|
||||
|
@ -1449,6 +1449,11 @@ fn parse_initializer(&parser p) -> option::t[ast::initializer] {
|
||||
ret some(rec(op = ast::init_assign,
|
||||
expr = parse_expr(p)));
|
||||
}
|
||||
case (token::LARROW) {
|
||||
p.bump();
|
||||
ret some(rec(op = ast::init_move,
|
||||
expr = parse_expr(p)));
|
||||
}
|
||||
// Now that the the channel is the first argument to receive,
|
||||
// combining it with an initializer doesn't really make sense.
|
||||
// case (token::RECV) {
|
||||
|
@ -6375,6 +6375,11 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
|
||||
auto sub = trans_expr(bcx, init.expr);
|
||||
bcx = copy_val(sub.bcx, INIT, llptr, sub.val, ty).bcx;
|
||||
}
|
||||
case (ast::init_move) {
|
||||
auto sub = trans_lval(bcx, init.expr);
|
||||
bcx = move_val(sub.res.bcx, INIT, llptr,
|
||||
sub.res.val, ty).bcx;
|
||||
}
|
||||
case (ast::init_recv) {
|
||||
bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx;
|
||||
}
|
||||
|
@ -2723,6 +2723,9 @@ fn check_decl_initializer(&@stmt_ctxt scx, &ast::def_id lid,
|
||||
case (ast::init_assign) {
|
||||
pushdown::pushdown_expr(scx, lty, init.expr);
|
||||
}
|
||||
case (ast::init_move) {
|
||||
pushdown::pushdown_expr(scx, lty, init.expr);
|
||||
}
|
||||
case (ast::init_recv) {
|
||||
auto port_ty = ty::mk_port(scx.fcx.ccx.tcx, lty);
|
||||
pushdown::pushdown_expr(scx, port_ty, init.expr);
|
||||
|
@ -865,9 +865,12 @@ fn print_decl(&ps s, &@ast::decl decl) {
|
||||
case (ast::init_assign) {
|
||||
word_space(s, "=");
|
||||
}
|
||||
case (ast::init_recv) {
|
||||
case (ast::init_move) {
|
||||
word_space(s, "<-");
|
||||
}
|
||||
case (ast::init_recv) {
|
||||
word_space(s, "|>");
|
||||
}
|
||||
}
|
||||
print_expr(s, init.expr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user