File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -39,13 +39,14 @@ let f = u.f1;
39
39
40
40
Unions have no notion of an "active field". Instead, every union access just
41
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 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:
49
50
50
51
``` rust
51
52
# union MyUnion { f1 : u32 , f2 : f32 }
You can’t perform that action at this time.
0 commit comments