Skip to content

Commit

Permalink
clarify validity requirement of end pointer in slice::from_ptr_range
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Nov 13, 2021
1 parent 5255902 commit 5eee5e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Free functions to create `&[T]` and `&mut [T]`.

use crate::array;
use crate::intrinsics::is_aligned_and_not_null;
use crate::mem;
use crate::ops::Range;
use crate::ptr;

Expand Down Expand Up @@ -195,7 +193,8 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
/// to the first element of a slice.
///
/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past*
/// the last element.
/// 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`:
///
Expand Down Expand Up @@ -251,7 +250,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
/// to the first element of a slice.
///
/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past*
/// the last element.
/// 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`:
///
Expand All @@ -274,7 +274,7 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
///
/// use core::slice;
///
/// let x = [1, 2, 3];
/// let mut x = [1, 2, 3];
/// let range = x.as_mut_ptr_range();
///
/// unsafe {
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,7 @@ fn slice_split_array_mut_out_of_bounds() {
v.split_array_mut::<7>();
}

#[test]
fn test_slice_from_ptr_range() {
let arr = ["foo".to_owned(), "bar".to_owned()];
let range = arr.as_ptr_range();
Expand Down

0 comments on commit 5eee5e5

Please sign in to comment.