Skip to content

Commit 20922ac

Browse files
committed
improve wording
1 parent c3d23c2 commit 20922ac

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/items/unions.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ let f = u.f1;
3838
```
3939

4040
Unions have no notion of an "active field". Instead, every union access just
41-
interprets the storage at the type of the field used for the access. The effect
42-
of reading a union with a different field than it was written to is that of
43-
calling [`transmute`]. Reading data at a bad type results in undefined behavior
44-
(for example, reading the value `3` at type `bool`).
45-
46-
However, which fields are safe to read and which not is generally not known
47-
statically, so all reads of union fields have to be placed in `unsafe` blocks.
41+
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 if the field. Reading data
44+
at a bad type results in undefined behavior (for example, reading the value `3`
45+
at type `bool`). For this reason, all reads of union fields have to be placed
46+
in `unsafe` blocks:
4847

4948
```rust
5049
# union MyUnion { f1: u32, f2: f32 }

0 commit comments

Comments
 (0)