]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/two-phase-sneaky.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / two-phase-sneaky.rs
1 // This is the first counter-example from Niko's blog post
2 // smallcultfollowing.com/babysteps/blog/2017/03/01/nested-method-calls-via-two-phase-borrowing/
3 // of a danger for code to crash if we just turned off the check for whether
4 // a mutable-borrow aliases another borrow.
5
6 fn main() {
7     let mut v: Vec<String> = vec![format!("Hello, ")];
8     v[0].push_str({
9
10         v.push(format!("foo"));
11         //~^   ERROR cannot borrow `v` as mutable more than once at a time [E0499]
12
13         "World!"
14     });
15 }