Skip to content

Commit 4cac94e

Browse files
committed
Auto merge of rust-lang#97419 - WaffleLapkin:const_from_ptr_range, r=oli-obk
Make `from{,_mut}_ptr_range` const This PR makes the following APIs `const`: ```rust // core::slice pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T]; pub const unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T]; ``` Tracking issue: rust-lang#89792. Feature for `from_ptr_range` as a `const fn`: `slice_from_ptr_range_const`. Feature for `from_mut_ptr_range` as a `const fn`: `slice_from_mut_ptr_range_const`. r? `@oli-obk`
2 parents 61ac8c1 + 805571e commit 4cac94e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
#![feature(ptr_sub_ptr)]
131131
#![feature(receiver_trait)]
132132
#![feature(set_ptr_value)]
133+
#![feature(slice_from_ptr_range)]
133134
#![feature(slice_group_by)]
134135
#![feature(slice_ptr_get)]
135136
#![feature(slice_ptr_len)]

alloc/src/slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ pub use core::slice::EscapeAscii;
114114
pub use core::slice::SliceIndex;
115115
#[stable(feature = "from_ref", since = "1.28.0")]
116116
pub use core::slice::{from_mut, from_ref};
117+
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
118+
pub use core::slice::{from_mut_ptr_range, from_ptr_range};
117119
#[stable(feature = "rust1", since = "1.0.0")]
118120
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
119121
#[stable(feature = "rust1", since = "1.0.0")]

core/src/slice/raw.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
213213
///
214214
/// [valid]: ptr#safety
215215
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
216-
pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
216+
#[rustc_const_unstable(feature = "const_slice_from_ptr_range", issue = "89792")]
217+
pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
217218
// SAFETY: the caller must uphold the safety contract for `from_ptr_range`.
218219
unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
219220
}
@@ -263,7 +264,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
263264
///
264265
/// [valid]: ptr#safety
265266
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
266-
pub unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] {
267+
#[rustc_const_unstable(feature = "slice_from_mut_ptr_range_const", issue = "89792")]
268+
pub const unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] {
267269
// SAFETY: the caller must uphold the safety contract for `from_mut_ptr_range`.
268270
unsafe { from_raw_parts_mut(range.start, range.end.sub_ptr(range.start)) }
269271
}

0 commit comments

Comments
 (0)