Skip to content

Commit dd8b7ee

Browse files
committed
wip: CR fixes
1 parent 540689b commit dd8b7ee

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

library/core/src/ptr/const_ptr.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1783,8 +1783,8 @@ impl<T, const N: usize> *const [T; N] {
17831783
/// assert_eq!(arr.as_ptr(), ptr::null());
17841784
/// ```
17851785
#[inline]
1786-
#[unstable(feature = "array_ptr_get", issue = "119411")]
1787-
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119411")]
1786+
#[unstable(feature = "array_ptr_get", issue = "119834")]
1787+
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")]
17881788
pub const fn as_ptr(self) -> *const T {
17891789
self as *const T
17901790
}
@@ -1801,11 +1801,10 @@ impl<T, const N: usize> *const [T; N] {
18011801
/// assert_eq!(slice.len(), 3);
18021802
/// ```
18031803
#[inline]
1804-
#[unstable(feature = "array_ptr_get", issue = "119411")]
1805-
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119411")]
1804+
#[unstable(feature = "array_ptr_get", issue = "119834")]
1805+
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")]
18061806
pub const fn as_slice(self) -> *const [T] {
1807-
// SAFETY: `N` is the length of the array, so the pointer is always in-bounds.
1808-
unsafe { slice::from_raw_parts(self.as_ptr(), N) }
1807+
slice_from_raw_parts(self.as_ptr(), N)
18091808
}
18101809
}
18111810

library/core/src/ptr/mut_ptr.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ impl<T> *mut [T] {
21982198
impl<T, const N: usize> *mut [T; N] {
21992199
/// Returns a raw pointer to the array's buffer.
22002200
///
2201-
/// This is equivalent to casting `self` to `*const T`, but more type-safe.
2201+
/// This is equivalent to casting `self` to `*mut T`, but more type-safe.
22022202
///
22032203
/// # Examples
22042204
///
@@ -2210,12 +2210,13 @@ impl<T, const N: usize> *mut [T; N] {
22102210
/// assert_eq!(arr.as_mut_ptr(), ptr::null_mut());
22112211
/// ```
22122212
#[inline]
2213-
#[unstable(feature = "array_ptr_get", issue = "119411")]
2214-
pub fn as_mut_ptr(self) -> *mut T {
2213+
#[unstable(feature = "array_ptr_get", issue = "119834")]
2214+
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")]
2215+
pub const fn as_mut_ptr(self) -> *mut T {
22152216
self as *mut T
22162217
}
22172218

2218-
/// Returns a raw pointer to a unique slice containing the entire array.
2219+
/// Returns a raw pointer to a mutable slice containing the entire array.
22192220
///
22202221
/// # Examples
22212222
///
@@ -2230,10 +2231,10 @@ impl<T, const N: usize> *mut [T; N] {
22302231
/// assert_eq!(arr, [3, 4, 5]);
22312232
/// ```
22322233
#[inline]
2233-
#[unstable(feature = "array_ptr_get", issue = "119411")]
2234-
pub fn as_mut_slice(self) -> *mut [T] {
2235-
// SAFETY: `N` is the length of the array, so the pointer is always in-bounds.
2236-
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), N) }
2234+
#[unstable(feature = "array_ptr_get", issue = "119834")]
2235+
#[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")]
2236+
pub const fn as_mut_slice(self) -> *mut [T] {
2237+
slice_from_raw_parts_mut(self.as_mut_ptr(), N)
22372238
}
22382239
}
22392240

library/core/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(alloc_layout_extra)]
22
#![feature(array_chunks)]
3+
#![feature(array_ptr_get)]
34
#![feature(array_windows)]
45
#![feature(ascii_char)]
56
#![feature(ascii_char_variants)]
@@ -49,6 +50,7 @@
4950
#![feature(sort_internals)]
5051
#![feature(slice_take)]
5152
#![feature(slice_from_ptr_range)]
53+
#![feature(slice_ptr_len)]
5254
#![feature(slice_split_once)]
5355
#![feature(split_as_slice)]
5456
#![feature(maybe_uninit_uninit_array)]

library/core/tests/ptr.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1142,3 +1142,16 @@ fn test_const_copy() {
11421142
assert!(*ptr2 == 1);
11431143
};
11441144
}
1145+
1146+
#[test]
1147+
fn test_null_array_as_slice() {
1148+
let arr: *mut [u8; 4] = null_mut();
1149+
let ptr: *mut [u8] = arr.as_mut_slice();
1150+
assert!(ptr.is_null());
1151+
assert_eq!(ptr.len(), 4);
1152+
1153+
let arr: *const [u8; 4] = null();
1154+
let ptr: *const [u8] = arr.as_slice();
1155+
assert!(ptr.is_null());
1156+
assert_eq!(ptr.len(), 4);
1157+
}

0 commit comments

Comments
 (0)