@@ -274,7 +274,8 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
274
274
/// size_of::<T>()` bytes must *not* overlap with the region of memory
275
275
/// beginning at `y` with the same size.
276
276
///
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.
278
279
///
279
280
/// [valid]: ../ptr/index.html#safety
280
281
///
@@ -369,7 +370,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
369
370
}
370
371
}
371
372
372
- /// Moves `src` into the pointed `dest `, returning the previous `dest ` value.
373
+ /// Moves `src` into the pointed `dst `, returning the previous `dst ` value.
373
374
///
374
375
/// Neither value is dropped.
375
376
///
@@ -383,9 +384,9 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
383
384
///
384
385
/// Behavior is undefined if any of the following conditions are violated:
385
386
///
386
- /// * `dest ` must be [valid] for writes.
387
+ /// * `dst ` must be [valid] for writes.
387
388
///
388
- /// * `dest ` must be properly aligned.
389
+ /// * `dst ` must be properly aligned.
389
390
///
390
391
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
391
392
///
@@ -409,8 +410,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
409
410
/// ```
410
411
#[ inline]
411
412
#[ 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
414
415
src
415
416
}
416
417
@@ -447,8 +448,8 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
447
448
///
448
449
/// let mut s = String::from("foo");
449
450
/// 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);
452
453
///
453
454
/// assert_eq!(s2, "foo");
454
455
///
@@ -558,7 +559,6 @@ pub unsafe fn read<T>(src: *const T) -> T {
558
559
/// use std::ptr;
559
560
///
560
561
/// #[repr(packed, C)]
561
- /// #[derive(Default)]
562
562
/// struct Packed {
563
563
/// _padding: u8,
564
564
/// unaligned: u32,
@@ -570,10 +570,11 @@ pub unsafe fn read<T>(src: *const T) -> T {
570
570
/// };
571
571
///
572
572
/// 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;
575
576
///
576
- /// // Dereferencing normally will emit an unaligned load instruction,
577
+ /// // Dereferencing normally will emit an aligned load instruction,
577
578
/// // causing undefined behavior.
578
579
/// // let v = *unaligned; // ERROR
579
580
///
0 commit comments