]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/two-phase-sneaky.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[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 }