Skip to content

Commit 917e073

Browse files
committed
Clarify union field borrowing
1 parent e504dd7 commit 917e073

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

text/0000-unnamed-fields.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ unnamed union will appear directly with the containing structure. Given a
9494
struct `s` of this type, code can access `s.a`, `s.d`, and either `s.b` or
9595
`s.c`. Accesses to `a` and `d` can occur in safe code; accesses to `b` and `c`
9696
require unsafe code, and `b` and `c` overlap, requiring care to access only the
97-
field whose contents make sense at the time. As with any `union`, code cannot
98-
borrow `s.b` and `s.c` simultaneously.
97+
field whose contents make sense at the time. As with any `union`, borrows of
98+
any `union` field borrow the entire union, so code cannot borrow `s.b` and
99+
`s.c` simultaneously if any of the borrows uses `&mut`.
99100

100101
Conversely, sometimes when defining a `union`, you may want to group multiple
101102
fields together and make them available simultaneously, with non-overlapping

0 commit comments

Comments
 (0)