mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
slice::from_raw_parts: mention no-wrap-around condition
This commit is contained in:
parent
de1ff0a8b5
commit
18b86468b8
@ -32,7 +32,8 @@ use crate::ptr;
|
||||
/// * The memory referenced by the returned slice must not be mutated for the duration
|
||||
/// of lifetime `'a`, except inside an `UnsafeCell`.
|
||||
///
|
||||
/// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`.
|
||||
/// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`,
|
||||
/// and adding that size to `data` must not "wrap around" the address space.
|
||||
/// See the safety documentation of [`pointer::offset`].
|
||||
///
|
||||
/// # Caveat
|
||||
@ -125,7 +126,8 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
|
||||
/// (not derived from the return value) for the duration of lifetime `'a`.
|
||||
/// Both read and write accesses are forbidden.
|
||||
///
|
||||
/// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`.
|
||||
/// * The total size `len * mem::size_of::<T>()` of the slice must be no larger than `isize::MAX`,
|
||||
/// and adding that size to `data` must not "wrap around" the address space.
|
||||
/// See the safety documentation of [`pointer::offset`].
|
||||
///
|
||||
/// [valid]: ptr#safety
|
||||
@ -179,15 +181,16 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
|
||||
/// 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`:
|
||||
/// * The entire memory range of this slice must be contained within a single allocated object!
|
||||
/// Slices can never span across multiple allocated objects.
|
||||
///
|
||||
/// * The entire memory range of this slice must be contained within a single allocated object!
|
||||
/// Slices can never span across multiple allocated objects.
|
||||
/// * The range must contain `N` consecutive properly initialized values of type `T`.
|
||||
///
|
||||
/// * The memory referenced by the returned slice must not be mutated for the duration
|
||||
/// of lifetime `'a`, except inside an `UnsafeCell`.
|
||||
///
|
||||
/// * The total length of the range must be no larger than `isize::MAX`.
|
||||
/// * The total length of the range must be no larger than `isize::MAX`,
|
||||
/// and adding that size to `data` must not "wrap around" the address space.
|
||||
/// See the safety documentation of [`pointer::offset`].
|
||||
///
|
||||
/// 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] {
|
||||
/// 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`:
|
||||
/// * The entire memory range of this slice must be contained within a single allocated object!
|
||||
/// Slices can never span across multiple allocated objects.
|
||||
///
|
||||
/// * The entire memory range of this slice must be contained within a single allocated object!
|
||||
/// Slices can never span across multiple allocated objects.
|
||||
/// * The range must contain `N` consecutive properly initialized values of type `T`.
|
||||
///
|
||||
/// * The memory referenced by the returned slice must not be accessed through any other pointer
|
||||
/// (not derived from the return value) for the duration of lifetime `'a`.
|
||||
/// Both read and write accesses are forbidden.
|
||||
///
|
||||
/// * The total length of the range must be no larger than `isize::MAX`.
|
||||
/// * The total length of the range must be no larger than `isize::MAX`,
|
||||
/// and adding that size to `data` must not "wrap around" the address space.
|
||||
/// See the safety documentation of [`pointer::offset`].
|
||||
///
|
||||
/// Note that a range created from [`slice::as_mut_ptr_range`] fulfills these requirements.
|
||||
|
Loading…
Reference in New Issue
Block a user