-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a temporary for assign_ops. Issue #2581
- Loading branch information
Showing
2 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// The cases commented as "Leaks" need to not leak. Issue #2581 | ||
|
||
impl methods<T: copy> for [T] { | ||
fn -(x: [T]/&) -> [T] { | ||
[x[0], x[0], x[0]] | ||
} | ||
|
||
fn foo(x: [T]/&) -> [T] { | ||
[x[0], x[0], x[0]] | ||
} | ||
} | ||
|
||
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 | ||
let mut bar = [1, 2, 3]; | ||
bar -= [3, 2, 1]; | ||
bar -= [4, 5, 6]; | ||
|
||
io::println(#fmt("%?", bar)); | ||
|
||
// okay | ||
let mut bar = [1, 2, 3]; | ||
bar = bar.foo([3, 2, 1]); | ||
bar = bar.foo([4, 5, 6]); | ||
|
||
io::println(#fmt("%?", bar)); | ||
|
||
// okay | ||
let mut bar = [1, 2, 3]; | ||
bar = bar - [3, 2, 1]; | ||
bar = bar - [4, 5, 6]; | ||
|
||
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)); | ||
|
||
} |