Skip to content

Commit 614f773

Browse files
Clarify some parts by applying the suggestions from review
Co-authored-by: Josh Triplett <[email protected]>
1 parent 2e21af2 commit 614f773

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libstd/keyword_docs.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1625,9 +1625,9 @@ mod dyn_keyword {}
16251625
/// The [Rust equivalent of a C-style union][union].
16261626
///
16271627
/// A `union` looks like a [`struct`] in terms of declaration, but all of its
1628-
/// fields exist simultaneously, superimposed over one another. For instance,
1628+
/// fields exist in the same memory, superimposed over one another. For instance,
16291629
/// if we wanted some bits in memory that we sometimes interpret as a `u32` and
1630-
/// sometimes as an `f32`, we would write:
1630+
/// sometimes as an `f32`, we could write:
16311631
///
16321632
/// ```rust
16331633
/// union IntOrFloat {
@@ -1647,6 +1647,7 @@ mod dyn_keyword {}
16471647
///
16481648
/// It is possible to use pattern matching on `union`s. A single field name must
16491649
/// be used and it must match the name of one of the `union`'s field.
1650+
/// Like reading from a `union`, pattern matching on a `union` requires `unsafe`.
16501651
///
16511652
/// ```rust
16521653
/// union IntOrFloat {
@@ -1658,17 +1659,17 @@ mod dyn_keyword {}
16581659
///
16591660
/// unsafe {
16601661
/// match u {
1661-
/// IntOrFloat { i: 10 } => println!("Found exactly ten !"),
1662-
/// // The field name is used to deduce the type
1662+
/// IntOrFloat { i: 10 } => println!("Found exactly ten!"),
1663+
/// // Matching the field `f` provides an `f32`.
16631664
/// IntOrFloat { f } => println!("Found f = {} !", f),
16641665
/// }
16651666
/// }
16661667
/// ```
16671668
///
16681669
/// # References to union fields
16691670
///
1670-
/// All fields in a union are all at the same place in memory which means
1671-
/// borrowing one borrows all of them, for the same duration:
1671+
/// All fields in a `union` are all at the same place in memory which means
1672+
/// borrowing one borrows the entire `union`, for the same lifetime:
16721673
///
16731674
/// ```rust,compile_fail,E0502
16741675
/// union IntOrFloat {

0 commit comments

Comments
 (0)