File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -38,13 +38,12 @@ let f = u.f1;
38
38
```
39
39
40
40
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:
48
47
49
48
``` rust
50
49
# union MyUnion { f1 : u32 , f2 : f32 }
You can’t perform that action at this time.
0 commit comments