rustc: Prevent destructors from being run twice with the repeated vector syntax
This commit is contained in:
parent
9ea6b3a32e
commit
1ed94a5674
@ -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);
|
||||
|
16
src/test/compile-fail/repeat-to-run-dtor-twice.rs
Normal file
16
src/test/compile-fail/repeat-to-run-dtor-twice.rs
Normal 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user