Add test cases for resources
This commit is contained in:
parent
07125aa38b
commit
fb14afd5eb
3 changed files with 25 additions and 1 deletions
|
@ -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
|
||||
// earlier pass.
|
||||
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) ||
|
||||
|
|
8
src/test/compile-fail/copy-a-resource.rs
Normal file
8
src/test/compile-fail/copy-a-resource.rs
Normal 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;
|
||||
}
|
16
src/test/run-pass/resource-destruct.rs
Normal file
16
src/test/run-pass/resource-destruct.rs
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue