@@ -32,7 +32,8 @@ use crate::ptr;
32
32
/// * The memory referenced by the returned slice must not be mutated for the duration
33
33
/// of lifetime `'a`, except inside an `UnsafeCell`.
34
34
///
35
- /// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`.
35
+ /// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`,
36
+ /// and adding that size to `data` must not "wrap around" the address space.
36
37
/// See the safety documentation of [`pointer::offset`].
37
38
///
38
39
/// # Caveat
@@ -125,7 +126,8 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
125
126
/// (not derived from the return value) for the duration of lifetime `'a`.
126
127
/// Both read and write accesses are forbidden.
127
128
///
128
- /// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`.
129
+ /// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`,
130
+ /// and adding that size to `data` must not "wrap around" the address space.
129
131
/// See the safety documentation of [`pointer::offset`].
130
132
///
131
133
/// [valid]: ptr#safety
@@ -179,15 +181,16 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
179
181
/// the last element, such that the offset from the end to the start pointer is
180
182
/// the length of the slice.
181
183
///
182
- /// * The range must contain `N` consecutive properly initialized values of type `T`:
184
+ /// * The entire memory range of this slice must be contained within a single allocated object!
185
+ /// Slices can never span across multiple allocated objects.
183
186
///
184
- /// * The entire memory range of this slice must be contained within a single allocated object!
185
- /// Slices can never span across multiple allocated objects.
187
+ /// * The range must contain `N` consecutive properly initialized values of type `T`.
186
188
///
187
189
/// * The memory referenced by the returned slice must not be mutated for the duration
188
190
/// of lifetime `'a`, except inside an `UnsafeCell`.
189
191
///
190
- /// * The total length of the range must be no larger than `isize::MAX`.
192
+ /// * The total length of the range must be no larger than `isize::MAX`,
193
+ /// and adding that size to `data` must not "wrap around" the address space.
191
194
/// See the safety documentation of [`pointer::offset`].
192
195
///
193
196
/// Note that a range created from [`slice::as_ptr_range`] fulfills these requirements.
@@ -247,16 +250,17 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
247
250
/// the last element, such that the offset from the end to the start pointer is
248
251
/// the length of the slice.
249
252
///
250
- /// * The range must contain `N` consecutive properly initialized values of type `T`:
253
+ /// * The entire memory range of this slice must be contained within a single allocated object!
254
+ /// Slices can never span across multiple allocated objects.
251
255
///
252
- /// * The entire memory range of this slice must be contained within a single allocated object!
253
- /// Slices can never span across multiple allocated objects.
256
+ /// * The range must contain `N` consecutive properly initialized values of type `T`.
254
257
///
255
258
/// * The memory referenced by the returned slice must not be accessed through any other pointer
256
259
/// (not derived from the return value) for the duration of lifetime `'a`.
257
260
/// Both read and write accesses are forbidden.
258
261
///
259
- /// * The total length of the range must be no larger than `isize::MAX`.
262
+ /// * The total length of the range must be no larger than `isize::MAX`,
263
+ /// and adding that size to `data` must not "wrap around" the address space.
260
264
/// See the safety documentation of [`pointer::offset`].
261
265
///
262
266
/// Note that a range created from [`slice::as_mut_ptr_range`] fulfills these requirements.
0 commit comments