mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #112704 - RalfJung:dont-wrap-slices, r=ChrisDenton
slice::from_raw_parts: mention no-wrap-around condition Cc https://github.com/rust-lang/rust/issues/83996. This probably needs to be mentioned in more places, so I am not closing that issue, but this here should help at least.
This commit is contained in:
@@ -32,7 +32,8 @@
|
||||
/// * 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 @@
|
||||
/// (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 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 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.
|
||||
|
||||
Reference in New Issue
Block a user