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