2019-09-01 12:09:59 -05:00
|
|
|
// Test that a borrow which starts as a two-phase borrow and gets
|
2018-04-06 19:48:13 -05:00
|
|
|
// carried around a loop winds up conflicting with itself.
|
|
|
|
|
|
|
|
struct Foo { x: String }
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn get_string(&mut self) -> &str {
|
|
|
|
&self.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut foo = Foo { x: format!("Hello, world") };
|
|
|
|
let mut strings = vec![];
|
|
|
|
|
|
|
|
loop {
|
|
|
|
strings.push(foo.get_string()); //~ ERROR cannot borrow `foo` as mutable
|
|
|
|
if strings.len() > 2 { break; }
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("{:?}", strings);
|
|
|
|
}
|