Skip to content

Commit 1f2c9ff

Browse files
rcseacordmanhatsu
authored andcommitted
Update types-and-traits.rst
1 parent 9a1153b commit 1f2c9ff

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
:id: non_compl_ex_UnionBool
5252
:status: draft
5353
54-
This noncompliant example reads a Boolean from a union field containing an invalid bit pattern.
55-
The value ``3`` is not a valid Boolean (only ``0`` and ``1`` are valid).
54+
This noncompliant example reads an invalid bit pattern from a Boolean union field.
55+
The value ``3`` is not a valid value of type ``bool`` (only ``0`` and ``1`` are valid).
5656
5757
.. code-block:: rust
5858
@@ -72,7 +72,7 @@
7272
:id: non_compl_ex_UnionChar
7373
:status: draft
7474
75-
This noncompliant example reads a ``char`` from a ``union`` containing an invalid Unicode value.
75+
This noncompliant example reads an invalid Unicode value from a ``union`` field of type ``char`` .
7676
7777
.. code-block:: rust
7878
@@ -121,7 +121,8 @@
121121
:id: non_compl_ex_UnionRef
122122
:status: draft
123123
124-
This noncompliant example reads a reference from a ``union`` containing a null or misaligned pointer.
124+
This noncompliant example reads a reference from a ``union`` containing a null pointer.
125+
A similar problem occurs when reading a misaligned pointer.
125126
126127
.. code-block:: rust
127128
@@ -133,8 +134,8 @@
133134
fn main() {
134135
let u = PtrOrRef { p: std::ptr::null() };
135136

136-
// Non-compliant: null is not a valid reference
137-
let invalid_ref = unsafe { u.r }; // UB: references cannot be null
137+
// Undefined behavior reading a null value from a reference field of a union
138+
unsafe { u.r }; // Noncompliant
138139
}
139140

140141
.. compliant_example::
@@ -196,7 +197,7 @@
196197
:id: compl_ex_UnionSameField
197198
:status: draft
198199

199-
This compliant solution read from the same field that was written.
200+
This compliant solution reads from the same field that was written.
200201

201202
.. code-block:: rust
202203

0 commit comments

Comments
 (0)