@@ -236,7 +236,7 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
236
236
///
237
237
/// * The two pointed-to values may overlap. If the values do overlap, then the
238
238
/// overlapping region of memory from `x` will be used. This is demonstrated
239
- /// in the examples below.
239
+ /// in the second example below.
240
240
///
241
241
/// [`mem::swap`]: ../mem/fn.swap.html
242
242
///
@@ -261,8 +261,8 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
261
261
///
262
262
/// let mut array = [0, 1, 2, 3];
263
263
///
264
- /// let x = array[0..].as_mut_ptr() as *mut [u32; 2];
265
- /// let y = array[2..].as_mut_ptr() as *mut [u32; 2];
264
+ /// let x = array[0..].as_mut_ptr() as *mut [u32; 2]; // this is `array[0..2]`
265
+ /// let y = array[2..].as_mut_ptr() as *mut [u32; 2]; // this is `array[2..4]`
266
266
///
267
267
/// unsafe {
268
268
/// ptr::swap(x, y);
@@ -277,11 +277,16 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
277
277
///
278
278
/// let mut array = [0, 1, 2, 3];
279
279
///
280
- /// let x = array[0..].as_mut_ptr() as *mut [u32; 3];
281
- /// let y = array[1..].as_mut_ptr() as *mut [u32; 3];
280
+ /// let x = array[0..].as_mut_ptr() as *mut [u32; 3]; // this is `array[0..3]`
281
+ /// let y = array[1..].as_mut_ptr() as *mut [u32; 3]; // this is `array[1..4]`
282
282
///
283
283
/// unsafe {
284
284
/// ptr::swap(x, y);
285
+ /// // The indices `1..3` of the slice overlap between `x` and `y`.
286
+ /// // Reasonable results would be for to them be `[2, 3]`, so that indices `0..3` are
287
+ /// // `[1, 2, 3]` (matching `y` before the `swap`); or for them to be `[0, 1]`
288
+ /// // so that indices `1..4` are `[0, 1, 2]` (matching `x` before the `swap`).
289
+ /// // This implementation is defined to make the latter choice.
285
290
/// assert_eq!([1, 0, 1, 2], array);
286
291
/// }
287
292
/// ```
0 commit comments