2012-06-13 15:45:12 -05:00
|
|
|
// The cases commented as "Leaks" need to not leak. Issue #2581
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
impl methods<T: copy> for ~[T] {
|
|
|
|
fn -(x: &[T]) -> ~[T] {
|
|
|
|
~[x[0], x[0], x[0]]
|
2012-06-13 15:45:12 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn foo(x: &[T]) -> ~[T] {
|
|
|
|
~[x[0], x[0], x[0]]
|
2012-06-13 15:45:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl methods<T: copy> for ~T {
|
|
|
|
fn +(rhs: ~T) -> ~T {
|
|
|
|
rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl methods for ~int {
|
|
|
|
fn -(rhs: ~int) -> ~int {
|
|
|
|
~(*self - *rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl methods for @int {
|
|
|
|
fn +(rhs: @int) -> @int {
|
|
|
|
@(*self + *rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// leaks
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut bar = ~[1, 2, 3];
|
|
|
|
bar -= ~[3, 2, 1];
|
|
|
|
bar -= ~[4, 5, 6];
|
2012-06-13 15:45:12 -05:00
|
|
|
|
|
|
|
io::println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
// okay
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut bar = ~[1, 2, 3];
|
|
|
|
bar = bar.foo(~[3, 2, 1]);
|
|
|
|
bar = bar.foo(~[4, 5, 6]);
|
2012-06-13 15:45:12 -05:00
|
|
|
|
|
|
|
io::println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
// okay
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut bar = ~[1, 2, 3];
|
|
|
|
bar = bar - ~[3, 2, 1];
|
|
|
|
bar = bar - ~[4, 5, 6];
|
2012-06-13 15:45:12 -05:00
|
|
|
|
|
|
|
io::println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
// Leaks
|
|
|
|
let mut bar = ~1;
|
|
|
|
bar += ~2;
|
|
|
|
bar += ~3;
|
|
|
|
|
|
|
|
io:: println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
// Leaks
|
|
|
|
let mut bar = ~1;
|
|
|
|
bar -= ~2;
|
|
|
|
bar -= ~3;
|
|
|
|
|
|
|
|
io:: println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
// Leaks
|
|
|
|
let mut bar = @1;
|
|
|
|
bar += @2;
|
|
|
|
bar += @3;
|
|
|
|
|
|
|
|
io:: println(#fmt("%?", bar));
|
|
|
|
|
|
|
|
}
|