diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-06-25 12:16:48 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-06-25 21:15:11 +0200 |
| commit | f6753be655770cc6fd02db9e5c63131a4536f95e (patch) | |
| tree | b081eb92d19a3f68d554c4d2f9d9e6ef1f4901f8 /src/comp | |
| parent | 61fc12d0d0d1b8acb7472bfc6223882b32acd3d2 (diff) | |
| download | rust-f6753be655770cc6fd02db9e5c63131a4536f95e.tar.gz rust-f6753be655770cc6fd02db9e5c63131a4536f95e.zip | |
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).
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/front/ast.rs | 7 | ||||
| -rw-r--r-- | src/comp/middle/tstate/pre_post_conditions.rs | 15 | ||||
| -rw-r--r-- | src/comp/middle/tstate/states.rs | 9 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index bfe7d576cfd..c601d799214 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -301,6 +301,13 @@ tag lit_ { 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. diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index e5eaadbb283..672894c0675 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -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, diff --git a/src/comp/middle/tstate/states.rs b/src/comp/middle/tstate/states.rs index 8af52ed83a0..386d1cff8a2 100644 --- a/src/comp/middle/tstate/states.rs +++ b/src/comp/middle/tstate/states.rs @@ -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, |
