Skip to content

Commit

Permalink
Add test case for #1894
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Mar 1, 2012
1 parent 1471b1f commit 072b015
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/test/run-pass/last-use-corner-cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fn main() {
// Make sure closing over can be a last use
let q = ~10;
let addr = ptr::addr_of(*q);
let f = fn@() -> *int { ptr::addr_of(*q) };
assert addr == f();

// But only when it really is the last use
let q = ~20;
let f = fn@() -> *int { ptr::addr_of(*q) };
assert ptr::addr_of(*q) != f();

// Ensure function arguments and box arguments interact sanely.
fn call_me(x: fn() -> int, y: ~int) { assert x() == *y; }
let q = ~30;
call_me({|| *q}, q);

// Check that no false positives are found in loops.
let q = ~40, p = 10;
while true {
let i = q;
p += *i;
if p > 100 { break; }
}

// Verify that blocks can't interfere with each other.
fn two_blocks(a: fn(), b: fn()) { a(); b(); a(); b(); }
let q = ~50;
two_blocks({|| let a = q; assert *a == 50;},
{|| let a = q; assert *a == 50;});
}

0 comments on commit 072b015

Please sign in to comment.