Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

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