Skip to content

Commit 1ed94a5

Browse files
committed
rustc: Prevent destructors from being run twice with the repeated vector syntax
1 parent 9ea6b3a commit 1ed94a5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/rustc/middle/kind.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
307307
}
308308
}
309309
}
310+
expr_repeat(element, count_expr, _) => {
311+
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
312+
if count == 1 {
313+
maybe_copy(cx, element);
314+
} else {
315+
let element_ty = ty::expr_ty(cx.tcx, element);
316+
check_copy(cx, element.id, element_ty, element.span, true);
317+
}
318+
}
310319
_ => { }
311320
}
312321
visit::visit_expr(e, cx, v);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Tests that one can't run a destructor twice with the repeated vector
2+
// literal syntax.
3+
4+
struct Foo {
5+
x: int;
6+
7+
drop {
8+
io::println("Goodbye!");
9+
}
10+
}
11+
12+
fn main() {
13+
let a = Foo { x: 3 };
14+
let b = [ a, ..5 ]; //~ ERROR copying a noncopyable value
15+
}
16+

0 commit comments

Comments
 (0)