rust/src/test/compile-fail/regions-escape-loop-via-vec.rs
Niko Matsakis 5d32d03b89 Fix #2979: inference for lifetimes of & expressions
What we now do is to create a region variable for each &
expression (and also each borrow).  The lifetime of this
variable will be checked by borrowck to ensure it is not greater
than the lifetime of the underlying data.  This both leads to
shorter lifetimes in some cases but also longer in others,
such as taking the address to the interior of unique boxes
tht are rooted in region pointers (e.g., returning a pointer
to the interior of a sendable map).

This may lead to issue #2977 if the rvalue is not POD, because
we may drop the data in trans sooner than borrowck expects us
to.  Need to work out precisely where that fix ought to occur.
2012-07-30 14:49:28 -07:00

13 lines
303 B
Rust

// The type of `y` ends up getting inferred to the type of the block.
fn broken() -> int {
let mut x = 3;
let mut y = ~[&mut x];
while x < 10 {
let mut z = x;
y += ~[&mut z]; //~ ERROR illegal borrow
x += 1;
}
vec::foldl(0, y, |v, p| v + *p )
}
fn main() { }