Skip to content

Commit 987728d

Browse files
authored
Update types-and-traits.rst
fixing up bibliography
1 parent 76f0b39 commit 987728d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/coding-guidelines/types-and-traits.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ Types and Traits
2121
:scope: system
2222
:tags: defect, safety, undefined-behavior
2323

24-
When reading from a union field, ensure that the underlying bytes constitute a valid value
25-
for that field's type.
26-
Reading a union field whose bytes do not represent a valid value
27-
for the field's type is undefined behavior.
24+
When reading from a union field, ensure that the underlying bytes constitute a valid value for that field's type.
25+
Reading a union field whose bytes do not represent a valid value for the field's type is undefined behavior.
2826

2927
Before accessing a union field:
3028

@@ -37,12 +35,12 @@ Types and Traits
3735
:status: draft
3836

3937
Unions allow multiple fields to occupy the same memory, similar to C unions.
40-
Unlike enums, unions do not track which field is currently active. It is the programmer's
41-
responsibility to ensure that when a field is read, the underlying bytes are valid for
42-
that field's type [RUST-REF-UNION]_.
38+
Unlike enumeration types, unions do not track which field is currently active.
39+
You must ensure that when a field is read,
40+
the underlying bytes are valid for that field's type [1]_.
4341

4442
Every type has a *validity invariant* — a set of constraints that all values of
45-
that type must satisfy [UCG-VALIDITY]_.
43+
that type must satisfy [2]_.
4644
Reading a union field performs a *typed read*,
4745
which asserts that the bytes are valid for the target type.
4846
Violating this invariant is undefined behavior.
@@ -294,13 +292,14 @@ Types and Traits
294292
:id: bib_UnionFieldValidity
295293
:status: draft
296294

295+
```rst
297296
.. list-table::
298297
:header-rows: 0
299-
:widths: 10 80
298+
:widths: 5 85
300299
301-
* - .. [RUST-REF-UNION]
300+
* - .. [1]
302301
- The Rust Project Developers. "Rust Reference: Unions." *The Rust Reference*, n.d. https://doc.rust-lang.org/reference/items/unions.html.
303-
* - .. [UCG-VALIDITY]
302+
* - .. [2]
304303
- Rust Unsafe Code Guidelines Working Group. "Validity and Safety Invariant." *Rust Unsafe Code Guidelines*, n.d. https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#validity-and-safety-invariant.
305304
306305
.. guideline:: Use strong types to differentiate between logically distinct values

0 commit comments

Comments
 (0)