Skip to content

Commit 5f15477

Browse files
committed
Prevent capturing non-copyable things in closures.
1 parent 6fa1a08 commit 5f15477

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

src/rustc/middle/kind.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
7171
// moved in or copied in
7272
check_send(cx, var_t, sp);
7373

74+
// copied in data must be copyable, but moved in data can be anything
75+
if !is_move { check_copy(cx, var_t, sp); }
76+
7477
// check that only immutable variables are implicitly copied in
7578
if !is_move {
7679
for fv.each { |fv|

src/rustdoc/fold.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn default_seq_fold_item<T>(
171171
doc
172172
}
173173

174-
fn default_any_fold_mod<T:send>(
174+
fn default_any_fold_mod<T:send copy>(
175175
fold: fold<T>,
176176
doc: doc::moddoc
177177
) -> doc::moddoc {
@@ -197,7 +197,7 @@ fn default_seq_fold_mod<T>(
197197
}
198198
}
199199

200-
fn default_par_fold_mod<T:send>(
200+
fn default_par_fold_mod<T:send copy>(
201201
fold: fold<T>,
202202
doc: doc::moddoc
203203
) -> doc::moddoc {
@@ -210,7 +210,7 @@ fn default_par_fold_mod<T:send>(
210210
}
211211
}
212212

213-
fn default_any_fold_nmod<T:send>(
213+
fn default_any_fold_nmod<T:send copy>(
214214
fold: fold<T>,
215215
doc: doc::nmoddoc
216216
) -> doc::nmoddoc {
@@ -236,7 +236,7 @@ fn default_seq_fold_nmod<T>(
236236
}
237237
}
238238

239-
fn default_par_fold_nmod<T:send>(
239+
fn default_par_fold_nmod<T:send copy>(
240240
fold: fold<T>,
241241
doc: doc::nmoddoc
242242
) -> doc::nmoddoc {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// error-pattern: copying a noncopyable value
2+
3+
use std;
4+
import std::arc;
5+
import comm::*;
6+
7+
fn main() {
8+
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
9+
let arc_v = arc::arc(v);
10+
11+
task::spawn() {||
12+
let v = *arc::get(&arc_v);
13+
assert v[3] == 4;
14+
};
15+
16+
assert (*arc::get(&arc_v))[2] == 3;
17+
18+
log(info, arc_v);
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// error-pattern: unsatisfied precondition constraint
2+
use std;
3+
import std::arc;
4+
import comm::*;
5+
6+
fn main() {
7+
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
8+
let arc_v = arc::arc(v);
9+
10+
task::spawn() {|move arc_v|
11+
let v = *arc::get(&arc_v);
12+
assert v[3] == 4;
13+
};
14+
15+
assert (*arc::get(&arc_v))[2] == 3;
16+
17+
log(info, arc_v);
18+
}

src/test/run-pass/uniq-cc-generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type pointy = {
88
d : fn~() -> uint,
99
};
1010

11-
fn make_uniq_closure<A:send>(a: A) -> fn~() -> uint {
11+
fn make_uniq_closure<A:send copy>(a: A) -> fn~() -> uint {
1212
fn~() -> uint { ptr::addr_of(a) as uint }
1313
}
1414

0 commit comments

Comments
 (0)