Skip to content

Commit 1149b30

Browse files
Rollup merge of #77097 - fusion-engineering-forks:slice-ptr-range-const-fn, r=oli-obk
Make [].as_[mut_]ptr_range() (unstably) const. Gated behind `const_ptr_offset`, as suggested by #65807 (comment) This also marks `[].as_mut_ptr()` as const, because it's used by `as_mut_ptr_range`. I gated it behind the same feature, because I figured it's not worth adding a separate tracking issue for const `as_mut_ptr`.
2 parents b49990c + 631c688 commit 1149b30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/core/src/slice/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,9 @@ impl<T> [T] {
433433
/// assert_eq!(x, &[3, 4, 6]);
434434
/// ```
435435
#[stable(feature = "rust1", since = "1.0.0")]
436+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
436437
#[inline]
437-
pub fn as_mut_ptr(&mut self) -> *mut T {
438+
pub const fn as_mut_ptr(&mut self) -> *mut T {
438439
self as *mut [T] as *mut T
439440
}
440441

@@ -469,8 +470,9 @@ impl<T> [T] {
469470
///
470471
/// [`as_ptr`]: #method.as_ptr
471472
#[unstable(feature = "slice_ptr_range", issue = "65807")]
473+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
472474
#[inline]
473-
pub fn as_ptr_range(&self) -> Range<*const T> {
475+
pub const fn as_ptr_range(&self) -> Range<*const T> {
474476
let start = self.as_ptr();
475477
// SAFETY: The `add` here is safe, because:
476478
//
@@ -510,8 +512,9 @@ impl<T> [T] {
510512
///
511513
/// [`as_mut_ptr`]: #method.as_mut_ptr
512514
#[unstable(feature = "slice_ptr_range", issue = "65807")]
515+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
513516
#[inline]
514-
pub fn as_mut_ptr_range(&mut self) -> Range<*mut T> {
517+
pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {
515518
let start = self.as_mut_ptr();
516519
// SAFETY: See as_ptr_range() above for why `add` here is safe.
517520
let end = unsafe { start.add(self.len()) };

0 commit comments

Comments
 (0)