Skip to content

Commit 548d552

Browse files
committed
Rollup merge of #27423 - oli-obk:patch-1, r=Gankro
2 parents ae9abdf + 6a86a0c commit 548d552

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/doc/tarpl/borrow-splitting.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ However borrowck doesn't understand arrays or slices in any way, so this doesn't
2727
work:
2828

2929
```rust,ignore
30-
let x = [1, 2, 3];
30+
let mut x = [1, 2, 3];
3131
let a = &mut x[0];
3232
let b = &mut x[1];
3333
println!("{} {}", a, b);
3434
```
3535

3636
```text
37-
<anon>:3:18: 3:22 error: cannot borrow immutable indexed content `x[..]` as mutable
38-
<anon>:3 let a = &mut x[0];
39-
^~~~
40-
<anon>:4:18: 4:22 error: cannot borrow immutable indexed content `x[..]` as mutable
41-
<anon>:4 let b = &mut x[1];
42-
^~~~
37+
<anon>:4:14: 4:18 error: cannot borrow `x[..]` as mutable more than once at a time
38+
<anon>:4 let b = &mut x[1];
39+
^~~~
40+
<anon>:3:14: 3:18 note: previous borrow of `x[..]` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x[..]` until the borrow ends
41+
<anon>:3 let a = &mut x[0];
42+
^~~~
43+
<anon>:6:2: 6:2 note: previous borrow ends here
44+
<anon>:1 fn main() {
45+
<anon>:2 let mut x = [1, 2, 3];
46+
<anon>:3 let a = &mut x[0];
47+
<anon>:4 let b = &mut x[1];
48+
<anon>:5 println!("{} {}", a, b);
49+
<anon>:6 }
50+
^
4351
error: aborting due to 2 previous errors
4452
```
4553

0 commit comments

Comments
 (0)