]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/two-phase-across-loop.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / two-phase-across-loop.rs
1 // Test that a borrow which starts as a two-phase borrow and gets
2 // carried around a loop winds up conflicting with itself.
3
4 struct Foo { x: String }
5
6 impl Foo {
7     fn get_string(&mut self) -> &str {
8         &self.x
9     }
10 }
11
12 fn main() {
13     let mut foo = Foo { x: format!("Hello, world") };
14     let mut strings = vec![];
15
16     loop {
17         strings.push(foo.get_string()); //~ ERROR cannot borrow `foo` as mutable
18         if strings.len() > 2 { break; }
19     }
20
21     println!("{:?}", strings);
22 }