Skip to content

Commit

Permalink
Rollup merge of #66477 - ALSchwalm:clarify-transmute-copy, r=Centril
Browse files Browse the repository at this point in the history
Clarify transmute_copy documentation example

Currently the documentation for `transmute_copy` implies that the function accepts a slice due to the variable name chosen in the example. This is misleading as `foo_slice` is actually an array and `transmute_copy` cannot take an unsized type anyway.

This PR just clarifies things by renaming the variable used in the example.
  • Loading branch information
JohnTitor committed Nov 17, 2019
2 parents 750dd03 + 3407c49 commit f65cb87
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,20 @@ pub fn drop<T>(_x: T) { }
/// bar: u8,
/// }
///
/// let foo_slice = [10u8];
/// let foo_array = [10u8];
///
/// unsafe {
/// // Copy the data from 'foo_slice' and treat it as a 'Foo'
/// let mut foo_struct: Foo = mem::transmute_copy(&foo_slice);
/// // Copy the data from 'foo_array' and treat it as a 'Foo'
/// let mut foo_struct: Foo = mem::transmute_copy(&foo_array);
/// assert_eq!(foo_struct.bar, 10);
///
/// // Modify the copied data
/// foo_struct.bar = 20;
/// assert_eq!(foo_struct.bar, 20);
/// }
///
/// // The contents of 'foo_slice' should not have changed
/// assert_eq!(foo_slice, [10]);
/// // The contents of 'foo_array' should not have changed
/// assert_eq!(foo_array, [10]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit f65cb87

Please sign in to comment.