Prevent capturing non-copyable things in closures.

This commit is contained in:
Eric Holk 2012-05-23 15:46:43 -07:00
parent 6fa1a084f7
commit 5f154770e2
5 changed files with 45 additions and 5 deletions

View File

@ -71,6 +71,9 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
// moved in or copied in
check_send(cx, var_t, sp);
// copied in data must be copyable, but moved in data can be anything
if !is_move { check_copy(cx, var_t, sp); }
// check that only immutable variables are implicitly copied in
if !is_move {
for fv.each { |fv|

View File

@ -171,7 +171,7 @@ fn default_seq_fold_item<T>(
doc
}
fn default_any_fold_mod<T:send>(
fn default_any_fold_mod<T:send copy>(
fold: fold<T>,
doc: doc::moddoc
) -> doc::moddoc {
@ -197,7 +197,7 @@ fn default_seq_fold_mod<T>(
}
}
fn default_par_fold_mod<T:send>(
fn default_par_fold_mod<T:send copy>(
fold: fold<T>,
doc: doc::moddoc
) -> doc::moddoc {
@ -210,7 +210,7 @@ fn default_par_fold_mod<T:send>(
}
}
fn default_any_fold_nmod<T:send>(
fn default_any_fold_nmod<T:send copy>(
fold: fold<T>,
doc: doc::nmoddoc
) -> doc::nmoddoc {
@ -236,7 +236,7 @@ fn default_seq_fold_nmod<T>(
}
}
fn default_par_fold_nmod<T:send>(
fn default_par_fold_nmod<T:send copy>(
fold: fold<T>,
doc: doc::nmoddoc
) -> doc::nmoddoc {

View File

@ -0,0 +1,19 @@
// error-pattern: copying a noncopyable value
use std;
import std::arc;
import comm::*;
fn main() {
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::arc(v);
task::spawn() {||
let v = *arc::get(&arc_v);
assert v[3] == 4;
};
assert (*arc::get(&arc_v))[2] == 3;
log(info, arc_v);
}

View File

@ -0,0 +1,18 @@
// error-pattern: unsatisfied precondition constraint
use std;
import std::arc;
import comm::*;
fn main() {
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::arc(v);
task::spawn() {|move arc_v|
let v = *arc::get(&arc_v);
assert v[3] == 4;
};
assert (*arc::get(&arc_v))[2] == 3;
log(info, arc_v);
}

View File

@ -8,7 +8,7 @@ type pointy = {
d : fn~() -> uint,
};
fn make_uniq_closure<A:send>(a: A) -> fn~() -> uint {
fn make_uniq_closure<A:send copy>(a: A) -> fn~() -> uint {
fn~() -> uint { ptr::addr_of(a) as uint }
}