blob: 5ff7b1242db702666dbcf91cf3c6b1adf17f241a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// edition:2021
// Tests that two closures cannot simultaneously have mutable
// and immutable access to the variable. Issue #6801.
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
fn a() {
let mut p = Point {x: 3, y:4};
let c2 = || p.y * 5;
let c1 = || {
//~^ ERROR cannot borrow `p` as mutable because it is also borrowed as immutable
dbg!(&p);
p.x = 4;
};
drop(c2);
}
fn main() {
}
|