Skip to content

Stabilize const versions of ptr::slice_from_raw_parts and slice::from_raw_parts. #94946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Regression test for issue #91827.

#![feature(const_ptr_offset_from)]
#![feature(const_slice_from_raw_parts)]
#![feature(extern_types)]

use std::ptr::addr_of;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
///
/// [`slice::from_raw_parts`]: crate::slice::from_raw_parts
#[unstable(feature = "ptr_metadata", issue = "81513")]
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
#[rustc_const_stable(feature = "ptr_metadata", since = "1.61.0")]
#[inline]
pub const fn from_raw_parts<T: ?Sized>(
data_address: *const (),
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub const fn null_mut<T>() -> *mut T {
/// ```
#[inline]
#[stable(feature = "slice_from_raw_parts", since = "1.42.0")]
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
#[rustc_const_stable(feature = "const_slice_from_raw_parts", since = "1.61.0")]
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
from_raw_parts(data.cast(), len)
}
Expand Down
7 changes: 3 additions & 4 deletions library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use crate::ptr;
/// [`NonNull::dangling()`]: ptr::NonNull::dangling
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
#[rustc_const_stable(feature = "const_slice_from_raw_parts", since = "1.61.0")]
#[must_use]
pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
debug_check_data_len(data, len);
Expand Down Expand Up @@ -135,8 +135,7 @@ pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a m

// In debug builds checks that `data` pointer is aligned and non-null and that slice with given `len` would cover less than half the address space
#[cfg(debug_assertions)]
#[unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
#[rustc_const_stable(feature = "const_slice_from_raw_parts", since = "1.61.0")]
const fn debug_check_data_len<T>(data: *const T, len: usize) {
fn rt_check<T>(data: *const T) {
use crate::intrinsics::is_aligned_and_not_null;
Expand All @@ -149,7 +148,7 @@ const fn debug_check_data_len<T>(data: *const T, len: usize) {
// SAFETY:
//
// `rt_check` is just a debug assert to hint users that they are causing UB,
// it is not required for safety (the safety must be guatanteed by
// it is not required for safety (the safety must be guaranteed by
// the `from_raw_parts[_mut]` caller).
//
// As per our safety precondition, we may assume that assertion above never fails.
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/issue-91827-extern-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Regression test for issue #91827.

#![feature(const_ptr_offset_from)]
#![feature(const_slice_from_raw_parts)]
#![feature(extern_types)]

use std::ptr::addr_of;
Expand Down