@@ -274,7 +274,8 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
274274/// size_of::<T>()` bytes must *not* overlap with the region of memory
275275/// beginning at `y` with the same size.
276276///
277- /// Note that even if `T` has size `0`, the pointers must be non-NULL and properly aligned.
277+ /// Note that even if the effectively copied size (`count * size_of::<T>()`) is `0`,
278+ /// the pointers must be non-NULL and properly aligned.
278279///
279280/// [valid]: ../ptr/index.html#safety
280281///
@@ -369,7 +370,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
369370 }
370371}
371372
372- /// Moves `src` into the pointed `dest `, returning the previous `dest ` value.
373+ /// Moves `src` into the pointed `dst `, returning the previous `dst ` value.
373374///
374375/// Neither value is dropped.
375376///
@@ -383,9 +384,9 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
383384///
384385/// Behavior is undefined if any of the following conditions are violated:
385386///
386- /// * `dest ` must be [valid] for writes.
387+ /// * `dst ` must be [valid] for writes.
387388///
388- /// * `dest ` must be properly aligned.
389+ /// * `dst ` must be properly aligned.
389390///
390391/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
391392///
@@ -409,8 +410,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
409410/// ```
410411#[ inline]
411412#[ stable( feature = "rust1" , since = "1.0.0" ) ]
412- pub unsafe fn replace < T > ( dest : * mut T , mut src : T ) -> T {
413- mem:: swap ( & mut * dest , & mut src) ; // cannot overlap
413+ pub unsafe fn replace < T > ( dst : * mut T , mut src : T ) -> T {
414+ mem:: swap ( & mut * dst , & mut src) ; // cannot overlap
414415 src
415416}
416417
@@ -447,8 +448,8 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
447448///
448449/// let mut s = String::from("foo");
449450/// unsafe {
450- /// // `s2` now points to the same underlying memory as `s1 `.
451- /// let mut s2 = ptr::read(&s);
451+ /// // `s2` now points to the same underlying memory as `s `.
452+ /// let mut s2: String = ptr::read(&s);
452453///
453454/// assert_eq!(s2, "foo");
454455///
@@ -558,7 +559,6 @@ pub unsafe fn read<T>(src: *const T) -> T {
558559/// use std::ptr;
559560///
560561/// #[repr(packed, C)]
561- /// #[derive(Default)]
562562/// struct Packed {
563563/// _padding: u8,
564564/// unaligned: u32,
@@ -570,10 +570,11 @@ pub unsafe fn read<T>(src: *const T) -> T {
570570/// };
571571///
572572/// let v = unsafe {
573- /// // Take a reference to a 32-bit integer which is not aligned.
574- /// let unaligned = &x.unaligned;
573+ /// // Take the address of a 32-bit integer which is not aligned.
574+ /// // This must be done as a raw pointer; unaligned references are invalid.
575+ /// let unaligned = &x.unaligned as *const u32;
575576///
576- /// // Dereferencing normally will emit an unaligned load instruction,
577+ /// // Dereferencing normally will emit an aligned load instruction,
577578/// // causing undefined behavior.
578579/// // let v = *unaligned; // ERROR
579580///
0 commit comments