rust/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs

19 lines
415 B
Rust
Raw Normal View History

2012-07-06 11:14:57 -05:00
fn borrow<T>(x: &T) -> &T {x}
fn foo(cond: fn() -> bool, box: fn() -> @int) {
let mut y: &int;
loop {
let x = box();
// Here we complain because the resulting region
// of this borrow is the fn body as a whole.
y = borrow(x); //~ ERROR illegal borrow: managed value would have to be rooted
2012-07-06 11:14:57 -05:00
assert *x == *y;
if cond() { break; }
2012-07-06 11:14:57 -05:00
}
assert *y != 0;
2012-07-06 11:14:57 -05:00
}
fn main() {}