1
Fork 0

Add test cases for resources

This commit is contained in:
Marijn Haverbeke 2011-06-28 17:47:56 +02:00
parent 07125aa38b
commit fb14afd5eb
3 changed files with 25 additions and 1 deletions

View file

@ -3137,7 +3137,7 @@ fn copy_val(&@block_ctxt cx, copy_action action, ValueRef dst, ValueRef src,
// FIXME this is just a clunky stopgap. we should do proper checking in an // FIXME this is just a clunky stopgap. we should do proper checking in an
// earlier pass. // earlier pass.
if (!ty::type_is_copyable(ccx.tcx, t)) { if (!ty::type_is_copyable(ccx.tcx, t)) {
ccx.sess.span_err(cx.sp, "Copying a non-copyable type."); ccx.sess.span_fatal(cx.sp, "Copying a non-copyable type.");
} }
if (ty::type_is_scalar(ccx.tcx, t) || if (ty::type_is_scalar(ccx.tcx, t) ||

View file

@ -0,0 +1,8 @@
// error-pattern:Copying a non-copyable type
res foo(int i) {}
fn main() {
auto x <- foo(10);
auto y = x;
}

View file

@ -0,0 +1,16 @@
res shrinky_pointer(@mutable int i) {
*i -= 1;
}
fn look_at(&shrinky_pointer pt) -> int {
ret **pt;
}
fn main() {
auto my_total = @mutable 10;
{
auto pt <- shrinky_pointer(my_total);
assert (look_at(pt) == 10);
}
assert (*my_total == 9);
}