You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit improves the logic for place descriptions in conflicting
borrow errors so that borrows of union fields have better messages even
when the unions are embedded in other unions or structs.
let mref = &mut r.r2_union.f3_union.s1_leaf.l1_u8;
42
+
// ^^^^^^^
43
+
*mref = 22;
44
+
let nref = &r.r2_union.f3_union.s2_leaf.l1_u8;
45
+
// ^^^^^^^
46
+
//~^^ ERROR cannot borrow `r.r2_union.f3_union` (via `r.r2_union.f3_union.s2_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f3_union.s1_leaf.l1_u8`) [E0502]
//~^^ ERROR cannot borrow `r.r2_union` (via `r.r2_union.f1_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f2_leaf.l1_u8`) [E0502]
error[E0502]: cannot borrow `r.r2_union.f3_union` (via `r.r2_union.f3_union.s2_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f3_union.s1_leaf.l1_u8`)
2
+
--> $DIR/issue-57100.rs:44:20
3
+
|
4
+
LL | let mref = &mut r.r2_union.f3_union.s1_leaf.l1_u8;
5
+
| -------------------------------------- mutable borrow occurs here (via `r.r2_union.f3_union.s1_leaf.l1_u8`)
6
+
...
7
+
LL | let nref = &r.r2_union.f3_union.s2_leaf.l1_u8;
8
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here (via `r.r2_union.f3_union.s2_leaf.l1_u8`)
9
+
...
10
+
LL | println!("{} {}", mref, nref)
11
+
| ---- mutable borrow later used here
12
+
13
+
error[E0502]: cannot borrow `r.r2_union` (via `r.r2_union.f1_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f2_leaf.l1_u8`)
14
+
--> $DIR/issue-57100.rs:62:20
15
+
|
16
+
LL | let mref = &mut r.r2_union.f2_leaf.l1_u8;
17
+
| ----------------------------- mutable borrow occurs here (via `r.r2_union.f2_leaf.l1_u8`)
18
+
...
19
+
LL | let nref = &r.r2_union.f1_leaf.l1_u8;
20
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here (via `r.r2_union.f1_leaf.l1_u8`)
21
+
...
22
+
LL | println!("{} {}", mref, nref)
23
+
| ---- mutable borrow later used here
24
+
25
+
error: aborting due to 2 previous errors
26
+
27
+
For more information about this error, try `rustc --explain E0502`.
0 commit comments