Skip to content

Commit 631c688

Browse files
committed
Make [].as_[mut_]ptr_range() (unstably) const.
1 parent 4eff9b0 commit 631c688

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/core/src/slice/mod.rs

+6-3
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)