diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index e02ee09c8af..ae7ff78b291 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -226,12 +226,28 @@ pub unsafe fn swap(x: *mut T, y: *mut T) { mem::forget(tmp); } -/// Swaps a sequence of values at two mutable locations of the same type. +/// Swaps `count * size_of::()` bytes between the two regions of memory +/// beginning at `x` and `y`. The two regions must *not* overlap. /// /// # Safety /// -/// The two arguments must each point to the beginning of `count` locations -/// of valid memory, and the two memory ranges must not overlap. +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * Both `x` and `y` must be [valid]. +/// +/// * Both `x` and `y` must be properly aligned. +/// +/// * `x.offset(count)` must be [valid]. In other words, the region of memory +/// which begins at `x` and has a length of `count * size_of::()` bytes +/// must belong to a single, live allocation. +/// +/// * `y.offset(count)` must be [valid]. In other words, the region of memory +/// which begins at `y` and has a length of `count * size_of::()` bytes +/// must belong to a single, live allocation. +/// +/// * The two regions of memory must *not* overlap. +/// +/// [valid]: ../ptr/index.html#safety /// /// # Examples ///