rustc: Prevent destructors from being run twice with the repeated vector syntax

This commit is contained in:
Patrick Walton 2012-08-17 16:12:07 -07:00
parent 9ea6b3a32e
commit 1ed94a5674
2 changed files with 25 additions and 0 deletions

View File

@ -307,6 +307,15 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
}
}
}
expr_repeat(element, count_expr, _) => {
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
if count == 1 {
maybe_copy(cx, element);
} else {
let element_ty = ty::expr_ty(cx.tcx, element);
check_copy(cx, element.id, element_ty, element.span, true);
}
}
_ => { }
}
visit::visit_expr(e, cx, v);

View File

@ -0,0 +1,16 @@
// Tests that one can't run a destructor twice with the repeated vector
// literal syntax.
struct Foo {
x: int;
drop {
io::println("Goodbye!");
}
}
fn main() {
let a = Foo { x: 3 };
let b = [ a, ..5 ]; //~ ERROR copying a noncopyable value
}