Skip to content

Commit f6753be

Browse files
committed
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).
1 parent 61fc12d commit f6753be

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/comp/front/ast.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ tag lit_ {
301301
lit_bool(bool);
302302
}
303303
304+
fn is_path(&@expr e) -> bool {
305+
ret alt (e.node) {
306+
case (expr_path(_)) { true }
307+
case (_) { false }
308+
};
309+
}
310+
304311
305312
// NB: If you change this, you'll probably want to change the corresponding
306313
// type structure in middle/ty.rs as well.

src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,12 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
367367
}
368368
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], e.id); }
369369
}
370-
forget_in_postcond(fcx, e.id, rhs.id);
370+
if (is_path(rhs)) {
371+
forget_in_postcond(fcx, e.id, rhs.id);
372+
}
371373
}
372374
case (expr_swap(?lhs, ?rhs)) {
373375
// Both sides must already be initialized
374-
375376
find_pre_post_exprs(fcx, [lhs, rhs], e.id);
376377
forget_in_postcond_still_init(fcx, e.id, lhs.id);
377378
forget_in_postcond_still_init(fcx, e.id, rhs.id);
@@ -591,14 +592,10 @@ fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) {
591592
rec(id=alocal.node.id,
592593
c=ninit(alocal.node.ident)));
593594

594-
alt (an_init.op) {
595-
case (init_move) {
596-
forget_in_postcond(fcx, id,
597-
an_init.expr.id);
598-
}
599-
case (_) { /* nothing gets deinitialized */ }
595+
if (an_init.op == init_move &&
596+
is_path(an_init.expr)) {
597+
forget_in_postcond(fcx, id, an_init.expr.id);
600598
}
601-
602599
}
603600
case (none) {
604601
clear_pp(node_id_to_ts_ann(fcx.ccx,

src/comp/middle/tstate/states.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,9 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
633633

634634
auto post = tritv_clone(expr_poststate(fcx.ccx,
635635
an_init.expr));
636-
alt (an_init.op) {
637-
case (init_move) {
638-
clear_in_poststate_expr(fcx, an_init.expr,
639-
post);
640-
}
641-
case (_) { /* nothing gets deinitialized */ }
636+
if (an_init.op == init_move) {
637+
clear_in_poststate_expr(fcx, an_init.expr,
638+
post);
642639
}
643640

644641
set_in_poststate_ident(fcx, alocal.node.id,

0 commit comments

Comments
 (0)