Skip to content

Commit d958bbc

Browse files
committed
---
yaml --- r: 36693 b: refs/heads/try2 c: 45848b2 h: refs/heads/master i: 36691: ff7aa45 v: v3
1 parent 37a6c26 commit d958bbc

File tree

8 files changed

+46
-24
lines changed

8 files changed

+46
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 7ca94369dad596421276c26ab98bdaa7bb1787cf
8+
refs/heads/try2: 45848b20402cb3ad07dd0b0442155ca9c6b14f01
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/librustc/middle/capture.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,29 @@ fn compute_capture_vars(tcx: ty::ctxt,
110110
// now go through anything that is referenced but was not explicitly
111111
// named and add that
112112

113-
let implicit_mode;
114-
if fn_proto == ast::ProtoBorrowed {
115-
implicit_mode = cap_ref;
116-
} else {
117-
implicit_mode = cap_copy;
118-
}
119-
113+
let implicit_mode_is_by_ref = fn_proto == ast::ProtoBorrowed;
120114
for vec::each(*freevars) |fvar| {
121115
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
122116
match cap_map.find(fvar_def_id) {
123117
option::Some(_) => { /* was explicitly named, do nothing */ }
124118
option::None => {
119+
// Move if this type implicitly moves; copy otherwise.
120+
let mode;
121+
if implicit_mode_is_by_ref {
122+
mode = cap_ref;
123+
} else {
124+
let fvar_ty = ty::node_id_to_type(tcx, fvar_def_id);
125+
if ty::type_implicitly_moves(tcx, fvar_ty) {
126+
mode = cap_move;
127+
} else {
128+
mode = cap_copy;
129+
}
130+
};
131+
125132
cap_map.insert(fvar_def_id, {def:fvar.def,
126133
span: fvar.span,
127134
cap_item: None,
128-
mode:implicit_mode});
135+
mode:mode});
129136
}
130137
}
131138
}

branches/try2/src/librustc/middle/kind.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
201201
let cap_def = cx.tcx.def_map.get(cap_item.id);
202202
let cap_def_id = ast_util::def_id_of_def(cap_def).node;
203203
let ty = ty::node_id_to_type(cx.tcx, cap_def_id);
204-
// Here's where is_move isn't always false...
205204
chk(cx, fn_id, None, cap_item.is_move, ty, cap_item.span);
206205
cap_def_id
207206
};
@@ -215,9 +214,12 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
215214
if captured_vars.contains(&id) { loop; }
216215

217216
let ty = ty::node_id_to_type(cx.tcx, id);
218-
// is_move is always false here. See the let captured_vars...
219-
// code above for where it's not always false.
220-
chk(cx, fn_id, Some(*fv), false, ty, fv.span);
217+
218+
// is_move is true if this type implicitly moves and false
219+
// otherwise.
220+
let is_move = ty::type_implicitly_moves(cx.tcx, ty);
221+
222+
chk(cx, fn_id, Some(*fv), is_move, ty, fv.span);
221223
}
222224
}
223225

branches/try2/src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) {
524524
// in better error messages than just pointing at the closure
525525
// construction site.
526526
let proto = ty::ty_fn_proto(ty::expr_ty(self.tcx, expr));
527-
let cvs = capture::compute_capture_vars(self.tcx, expr.id,
528-
proto, cap_clause);
527+
let cvs = capture::compute_capture_vars(self.tcx, expr.id, proto,
528+
cap_clause);
529529
let mut call_caps = ~[];
530530
for cvs.each |cv| {
531531
match relevant_def(cv.def) {

branches/try2/src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ fn trans_arg_expr(bcx: block,
621621
let arg_ty = expr_ty(bcx, arg_expr);
622622
let proto = ty::ty_fn_proto(arg_ty);
623623
let bcx = closure::trans_expr_fn(
624-
bcx, proto, decl, (*body), blk.id,
625-
cap, Some(ret_flag), expr::SaveIn(scratch));
624+
bcx, proto, decl, (*body), blk.id, cap,
625+
Some(ret_flag), expr::SaveIn(scratch));
626626
DatumBlock {bcx: bcx,
627627
datum: Datum {val: scratch,
628628
ty: scratch_ty,

branches/try2/src/librustc/middle/trans/expr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,8 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
549549
ast::expr_fn(proto, decl, ref body, cap_clause) => {
550550
// Don't use this function for anything real. Use the one in
551551
// astconv instead.
552-
return closure::trans_expr_fn(bcx, proto,
553-
decl, (*body), expr.id, cap_clause,
554-
None, dest);
552+
return closure::trans_expr_fn(bcx, proto, decl, *body, expr.id,
553+
cap_clause, None, dest);
555554
}
556555
ast::expr_fn_block(decl, ref body, cap_clause) => {
557556
let expr_ty = expr_ty(bcx, expr);
@@ -561,9 +560,8 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
561560
expr_to_str(expr, tcx.sess.intr()),
562561
ty_to_str(tcx, expr_ty));
563562
return closure::trans_expr_fn(
564-
bcx, fn_ty.meta.proto, decl, (*body),
565-
expr.id, cap_clause, None,
566-
dest);
563+
bcx, fn_ty.meta.proto, decl, *body, expr.id,
564+
cap_clause, None, dest);
567565
}
568566
_ => {
569567
bcx.sess().impossible_case(
@@ -577,7 +575,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
577575
match blk.node {
578576
ast::expr_fn_block(decl, ref body, cap) => {
579577
return closure::trans_expr_fn(
580-
bcx, fn_ty.meta.proto, decl, (*body), blk.id,
578+
bcx, fn_ty.meta.proto, decl, *body, blk.id,
581579
cap, Some(None), dest);
582580
}
583581
_ => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let x = ~"Hello world!";
3+
do task::spawn {
4+
io::println(x);
5+
}
6+
io::println(x); //~ ERROR use of moved variable
7+
}
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let x = ~"Hello world!";
3+
do task::spawn {
4+
io::println(x);
5+
}
6+
}
7+

0 commit comments

Comments
 (0)