Skip to content

Commit 18084be

Browse files
committed
auto merge of #10772 : alexcrichton/rust/issue-3053, r=alexcrichton
Rebasing #10446 with a `pub fn main`
2 parents fc3b7c1 + 7067561 commit 18084be

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// exec-env:RUST_POISON_ON_FREE=1
2+
3+
// Test that we root `x` even though it is found in immutable memory,
4+
// because it is moved.
5+
6+
#[feature(managed_boxes)];
7+
8+
fn free<T>(x: @T) {}
9+
10+
struct Foo {
11+
f: @Bar
12+
}
13+
14+
struct Bar {
15+
g: int
16+
}
17+
18+
fn lend(x: @Foo) -> int {
19+
let y = &x.f.g;
20+
free(x); // specifically here, if x is not rooted, it will be freed
21+
*y
22+
}
23+
24+
pub fn main() {
25+
assert_eq!(lend(@Foo {f: @Bar {g: 22}}), 22);
26+
}

0 commit comments

Comments
 (0)