mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
23 lines
496 B
Rust
23 lines
496 B
Rust
// Test that a borrow which starts as a two-phase borrow and gets
|
|
// 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);
|
|
}
|