mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 04:56:25 +03:00
Add test cases for resources
This commit is contained in:
@@ -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) ||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// error-pattern:Copying a non-copyable type
|
||||
|
||||
res foo(int i) {}
|
||||
|
||||
fn main() {
|
||||
auto x <- foo(10);
|
||||
auto y = x;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user