File tree Expand file tree Collapse file tree 1 file changed +0
-12
lines changed Expand file tree Collapse file tree 1 file changed +0
-12
lines changed Original file line number Diff line number Diff line change 4
4
represents the consensus from issue [ #73 ] . The statements in here are not (yet)
5
5
"guaranteed" not to change until an RFC ratifies them.
6
6
7
- The bit ` i ` of an union is allowed to have value ` v ` _ iff_ there is a variant of
8
- the union such that bit ` i ` of the variant is allowed to have value ` v ` . We
9
- assume all variants to be "filled up" to the same size with padding, which may
10
- have any value.
11
-
12
7
## Validity of unions with zero-sized fields
13
8
14
9
A union containing a zero-sized field can contain any value. An example of such
15
10
an union is [ ` MaybeUninit ` ] .
16
11
17
- <details ><summary ><b >Rationale</b ></summary >
18
-
19
- This follows from the definition of the values that ` union ` bits are allowed to
20
- take. The zero-sized type has size ` 0 ` , and its variant is filled up to
21
- the ` union ` size with padding. Since padding is allowed to take any value, any
22
- bit in the ` union ` is allowed to take any value.
23
-
24
12
[ #73 ] : https://github.com/rust-lang/unsafe-code-guidelines/issues/73
25
13
[ `MaybeUninit` ] : https://doc.rust-lang.org/std/mem/union.MaybeUninit.html
You can’t perform that action at this time.
0 commit comments