Skip to content

Commit

Permalink
Add test for rust-lang#3053. Fixes rust-lang#3053.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis authored and alexcrichton committed Dec 2, 2013
1 parent 61443dc commit 7067561
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/run-pass/borrowck-preserve-box-in-moved-value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// exec-env:RUST_POISON_ON_FREE=1

// Test that we root `x` even though it is found in immutable memory,
// because it is moved.

#[feature(managed_boxes)];

fn free<T>(x: @T) {}

struct Foo {
f: @Bar
}

struct Bar {
g: int
}

fn lend(x: @Foo) -> int {
let y = &x.f.g;
free(x); // specifically here, if x is not rooted, it will be freed
*y
}

pub fn main() {
assert_eq!(lend(@Foo {f: @Bar {g: 22}}), 22);
}

1 comment on commit 7067561

@alexcrichton
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+, just a test

Please sign in to comment.