File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 11//! Free functions to create `&[T]` and `&mut [T]`.
22
33use crate :: array;
4- use crate :: intrinsics:: is_aligned_and_not_null;
5- use crate :: mem;
64use crate :: ops:: Range ;
75use crate :: ptr;
86
@@ -195,7 +193,8 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
195193/// to the first element of a slice.
196194///
197195/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past*
198- /// the last element.
196+ /// the last element, such that the offset from the end to the start pointer is
197+ /// the length of the slice.
199198///
200199/// * The range must contain `N` consecutive properly initialized values of type `T`:
201200///
@@ -251,7 +250,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
251250/// to the first element of a slice.
252251///
253252/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past*
254- /// the last element.
253+ /// the last element, such that the offset from the end to the start pointer is
254+ /// the length of the slice.
255255///
256256/// * The range must contain `N` consecutive properly initialized values of type `T`:
257257///
@@ -274,7 +274,7 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
274274///
275275/// use core::slice;
276276///
277- /// let x = [1, 2, 3];
277+ /// let mut x = [1, 2, 3];
278278/// let range = x.as_mut_ptr_range();
279279///
280280/// unsafe {
Original file line number Diff line number Diff line change @@ -2234,6 +2234,7 @@ fn slice_split_array_mut_out_of_bounds() {
22342234 v. split_array_mut :: < 7 > ( ) ;
22352235}
22362236
2237+ #[ test]
22372238fn test_slice_from_ptr_range ( ) {
22382239 let arr = [ "foo" . to_owned ( ) , "bar" . to_owned ( ) ] ;
22392240 let range = arr. as_ptr_range ( ) ;
You can’t perform that action at this time.
0 commit comments