Skip to content

Commit 9f9313f

Browse files
committed
improve wording
1 parent f85beb5 commit 9f9313f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/items/unions.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ let f = u.f1;
3939

4040
Unions have no notion of an "active field". Instead, every union access just
4141
interprets the storage at the type of the field used for the access. Reading a
42-
union field is equivalent to a [`transmute`]: The data in the union, no matter
43-
how it was stored there, is transmuted to the type of the field. Just like with
44-
any other transmute, it is the programmer's responsibility to make sure that the
45-
data is valid at the field's type. Failing to do so results in undefined
46-
behavior (for example, reading the value `3` at type `bool` is undefined
47-
behavior). For this reason, all reads of union fields have to be placed in
48-
`unsafe` blocks:
42+
union field reads the bits of the union at the field's type. It is the
43+
programmer's responsibility to make sure that the data is valid at that
44+
type. Failing to do so results in undefined behavior (for example, reading the
45+
value `3` at type `bool` is undefined behavior). Effectively, writing to and
46+
then reading from a union is equivalent to a [`transmute`] from the type used
47+
for writing to the type used for reading.
48+
49+
Consequently, all reads of union fields have to be placed in `unsafe` blocks:
4950

5051
```rust
5152
# union MyUnion { f1: u32, f2: f32 }

0 commit comments

Comments
 (0)