@@ -1694,6 +1694,16 @@ if they meet one of the following criteria:
1694
1694
- so: writing a path like ` a ` is illegal if ` a.b ` is borrowed
1695
1695
- but: writing ` a ` is legal if ` *a ` is borrowed, whether or not ` a `
1696
1696
is a shared or mutable reference
1697
+ - the loan path has a ** shallow prefix** ` <base>.<field1> ` that accesses a
1698
+ field of a union, and ` lvalue ` has a prefix of the form ` <base>.<field2> `
1699
+ for a _ different_ field of the same base union.
1700
+ - so: if ` s.u ` is a union with distinct fields ` a ` and ` b ` , shallowly
1701
+ accessing a path ` s.u.a.x ` is illegal if ` s.u.b ` or ` s.u.b.y ` is borrowed.
1702
+ In here, ` <base> ` is ` s.u ` , ` <field1> ` is ` b ` and ` <field2> ` is ` a ` .
1703
+ - but: unless ` s.u.a ` is _ also_ a union, the access ` s.u.a.x ` is _ legal_
1704
+ if ` s.u.a.z ` is borrowed, because the same union field is used in both borrows.
1705
+ - the prefix of ` lvalue ` can be an arbitrary prefix - if ` s.u.b.w ` is borrowed,
1706
+ then it is illegal to shallowly access ` *(*s.u.a.z).t `
1697
1707
1698
1708
For ** deep** accesses to the path ` lvalue ` , we consider borrows relevant
1699
1709
if they meet one of the following criteria:
@@ -1707,6 +1717,14 @@ if they meet one of the following criteria:
1707
1717
- so: reading a path like ` a ` is illegal if ` a.b ` is mutably
1708
1718
borrowed, but -- in contrast with shallow accesses -- reading ` a ` is also
1709
1719
illegal if ` *a ` is mutably borrowed
1720
+ - the loan path has a ** supporting prefix** ` <base>.<field1> ` that accesses a
1721
+ field of a union, and ` lvalue ` has a prefix of the form ` <base>.<field2> ` for
1722
+ a _ different_ field with the same base union.
1723
+ - so: if ` s.u ` is a union with distinct fields ` a ` and ` b ` , deeply accessing
1724
+ a path ` s.u.a.x ` is illegal if ` s.u.b ` , ` s.u.b.w ` , or (in contrast with
1725
+ shallow accesses, and as long as both dereferences are of the form ` &mut T ` )
1726
+ ` *(*s.u.b.w).t ` is borrowed. In here, ` <base> ` is ` s.u ` , ` <field1> ` is ` b ` ,
1727
+ and ` <field2> ` is ` a ` .
1710
1728
1711
1729
** Dropping an lvalue LV.** Dropping an lvalue can be treated as a DEEP
1712
1730
WRITE, like a move, but this is overly conservative. The rules here
0 commit comments