|
1 | 1 | //! Free functions to create `&[T]` and `&mut [T]`.
|
2 | 2 |
|
3 | 3 | use crate::array;
|
| 4 | +/* |
4 | 5 | use crate::intrinsics::{
|
5 | 6 | assert_unsafe_precondition, is_aligned_and_not_null, is_valid_allocation_size,
|
6 | 7 | };
|
| 8 | +*/ |
7 | 9 | use crate::ops::Range;
|
8 | 10 | use crate::ptr;
|
9 | 11 |
|
@@ -94,11 +96,13 @@ use crate::ptr;
|
94 | 96 | pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
|
95 | 97 | // SAFETY: the caller must uphold the safety contract for `from_raw_parts`.
|
96 | 98 | unsafe {
|
| 99 | + /* |
97 | 100 | assert_unsafe_precondition!(
|
98 | 101 | "slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`",
|
99 | 102 | [T](data: *const T, len: usize) => is_aligned_and_not_null(data)
|
100 | 103 | && is_valid_allocation_size::<T>(len)
|
101 | 104 | );
|
| 105 | + */ |
102 | 106 | &*ptr::slice_from_raw_parts(data, len)
|
103 | 107 | }
|
104 | 108 | }
|
@@ -141,11 +145,13 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
|
141 | 145 | pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
|
142 | 146 | // SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`.
|
143 | 147 | unsafe {
|
| 148 | + /* |
144 | 149 | assert_unsafe_precondition!(
|
145 | 150 | "slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`",
|
146 | 151 | [T](data: *mut T, len: usize) => is_aligned_and_not_null(data)
|
147 | 152 | && is_valid_allocation_size::<T>(len)
|
148 | 153 | );
|
| 154 | + */ |
149 | 155 | &mut *ptr::slice_from_raw_parts_mut(data, len)
|
150 | 156 | }
|
151 | 157 | }
|
|
0 commit comments