Properly cleanup slice literals. Closes #2705.
This commit is contained in:
parent
f17ca3f73e
commit
51468b65a4
2 changed files with 22 additions and 0 deletions
|
@ -152,8 +152,15 @@ fn trans_evec(bcx: block, args: [@ast::expr]/~,
|
||||||
}
|
}
|
||||||
ast::vstore_slice(_) {
|
ast::vstore_slice(_) {
|
||||||
let n = vec::len(args);
|
let n = vec::len(args);
|
||||||
|
// Make a fake type to use for the cleanup
|
||||||
|
let ty = ty::mk_evec(bcx.tcx(),
|
||||||
|
{ty: unit_ty, mutbl: ast::m_mutbl},
|
||||||
|
ty::vstore_fixed(n));
|
||||||
|
|
||||||
let n = C_uint(ccx, n);
|
let n = C_uint(ccx, n);
|
||||||
let vp = base::arrayalloca(bcx, llunitty, n);
|
let vp = base::arrayalloca(bcx, llunitty, n);
|
||||||
|
add_clean(bcx, vp, ty);
|
||||||
|
|
||||||
let len = Mul(bcx, n, unit_sz);
|
let len = Mul(bcx, n, unit_sz);
|
||||||
|
|
||||||
let p = base::alloca(bcx, T_struct([T_ptr(llunitty),
|
let p = base::alloca(bcx, T_struct([T_ptr(llunitty),
|
||||||
|
|
15
src/test/run-pass/vec-slice-drop.rs
Normal file
15
src/test/run-pass/vec-slice-drop.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Make sure that destructors get run on slice literals
|
||||||
|
class foo {
|
||||||
|
let x: @mut int;
|
||||||
|
new(x: @mut int) { self.x = x; }
|
||||||
|
drop { *self.x += 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = @mut 0;
|
||||||
|
{
|
||||||
|
let l = [foo(x)]/&;
|
||||||
|
assert *l[0].x == 0;
|
||||||
|
}
|
||||||
|
assert *x == 1;
|
||||||
|
}
|
Loading…
Reference in a new issue