diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index 3a8d7987aca8b..d21113104b772 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -1,8 +1,6 @@ //! Free functions to create `&[T]` and `&mut [T]`. use crate::array; -use crate::intrinsics::is_aligned_and_not_null; -use crate::mem; use crate::ops::Range; use crate::ptr; @@ -195,7 +193,8 @@ pub const fn from_mut(s: &mut T) -> &mut [T] { /// to the first element of a slice. /// /// * The `end` pointer must be a [valid] and properly aligned pointer to *one past* -/// the last element. +/// the last element, such that the offset from the end to the start pointer is +/// the length of the slice. /// /// * The range must contain `N` consecutive properly initialized values of type `T`: /// @@ -251,7 +250,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] { /// to the first element of a slice. /// /// * The `end` pointer must be a [valid] and properly aligned pointer to *one past* -/// the last element. +/// the last element, such that the offset from the end to the start pointer is +/// the length of the slice. /// /// * The range must contain `N` consecutive properly initialized values of type `T`: /// @@ -274,7 +274,7 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] { /// /// use core::slice; /// -/// let x = [1, 2, 3]; +/// let mut x = [1, 2, 3]; /// let range = x.as_mut_ptr_range(); /// /// unsafe { diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 47b4b47793a42..96dda312de75f 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -2234,6 +2234,7 @@ fn slice_split_array_mut_out_of_bounds() { v.split_array_mut::<7>(); } +#[test] fn test_slice_from_ptr_range() { let arr = ["foo".to_owned(), "bar".to_owned()]; let range = arr.as_ptr_range();