]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-assign-comp-idx.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-assign-comp-idx.rs
1 struct Point {
2     x: isize,
3     y: isize,
4 }
5
6 fn a() {
7     let mut p = vec![1];
8
9     // Create an immutable pointer into p's contents:
10     let q: &isize = &p[0];
11
12     p[0] = 5; //~ ERROR cannot borrow
13
14     println!("{}", *q);
15 }
16
17 fn borrow<F>(_x: &[isize], _f: F) where F: FnOnce() {}
18
19 fn b() {
20     // here we alias the mutable vector into an imm slice and try to
21     // modify the original:
22
23     let mut p = vec![1];
24
25     borrow(
26         &p,
27         || p[0] = 5); //~ ERROR cannot borrow `p` as mutable
28 }
29
30 fn c() {
31     // Legal because the scope of the borrow does not include the
32     // modification:
33     let mut p = vec![1];
34     borrow(&p, ||{});
35     p[0] = 5;
36 }
37
38 fn main() {
39 }