Allow moving out of temporary values
This will probably need more work, as moving doesn't appear to do quite the right thing yet in general, and we should also check somewhere that we're not, for example, moving out the content out of an immutable field (probably moving out of fields is not okay in general).
This commit is contained in:
parent
61fc12d0d0
commit
f6753be655
@ -301,6 +301,13 @@ fn unop_to_str(unop op) -> str {
|
||||
lit_bool(bool);
|
||||
}
|
||||
|
||||
fn is_path(&@expr e) -> bool {
|
||||
ret alt (e.node) {
|
||||
case (expr_path(_)) { true }
|
||||
case (_) { false }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// NB: If you change this, you'll probably want to change the corresponding
|
||||
// type structure in middle/ty.rs as well.
|
||||
|
@ -367,11 +367,12 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], e.id); }
|
||||
}
|
||||
forget_in_postcond(fcx, e.id, rhs.id);
|
||||
if (is_path(rhs)) {
|
||||
forget_in_postcond(fcx, e.id, rhs.id);
|
||||
}
|
||||
}
|
||||
case (expr_swap(?lhs, ?rhs)) {
|
||||
// Both sides must already be initialized
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], e.id);
|
||||
forget_in_postcond_still_init(fcx, e.id, lhs.id);
|
||||
forget_in_postcond_still_init(fcx, e.id, rhs.id);
|
||||
@ -591,14 +592,10 @@ fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) {
|
||||
rec(id=alocal.node.id,
|
||||
c=ninit(alocal.node.ident)));
|
||||
|
||||
alt (an_init.op) {
|
||||
case (init_move) {
|
||||
forget_in_postcond(fcx, id,
|
||||
an_init.expr.id);
|
||||
}
|
||||
case (_) { /* nothing gets deinitialized */ }
|
||||
if (an_init.op == init_move &&
|
||||
is_path(an_init.expr)) {
|
||||
forget_in_postcond(fcx, id, an_init.expr.id);
|
||||
}
|
||||
|
||||
}
|
||||
case (none) {
|
||||
clear_pp(node_id_to_ts_ann(fcx.ccx,
|
||||
|
@ -633,12 +633,9 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
|
||||
|
||||
auto post = tritv_clone(expr_poststate(fcx.ccx,
|
||||
an_init.expr));
|
||||
alt (an_init.op) {
|
||||
case (init_move) {
|
||||
clear_in_poststate_expr(fcx, an_init.expr,
|
||||
post);
|
||||
}
|
||||
case (_) { /* nothing gets deinitialized */ }
|
||||
if (an_init.op == init_move) {
|
||||
clear_in_poststate_expr(fcx, an_init.expr,
|
||||
post);
|
||||
}
|
||||
|
||||
set_in_poststate_ident(fcx, alocal.node.id,
|
||||
|
Loading…
Reference in New Issue
Block a user