Skip to content

Commit 7594d2a

Browse files
committed
Constify ptr::read and ptr::read_unaligned
1 parent 1b77f8e commit 7594d2a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#![feature(const_assert_type)]
7474
#![feature(const_discriminant)]
7575
#![feature(const_cell_into_inner)]
76+
#![feature(const_intrinsic_copy)]
7677
#![feature(const_checked_int_methods)]
7778
#![feature(const_euclidean_int_methods)]
7879
#![feature(const_float_classify)]

library/core/src/ptr/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
685685
/// [valid]: self#safety
686686
#[inline]
687687
#[stable(feature = "rust1", since = "1.0.0")]
688-
pub unsafe fn read<T>(src: *const T) -> T {
688+
#[rustc_const_unstable(feature = "const_ptr_read", issue = "none")]
689+
pub const unsafe fn read<T>(src: *const T) -> T {
689690
// `copy_nonoverlapping` takes care of debug_assert.
690691
let mut tmp = MaybeUninit::<T>::uninit();
691692
// SAFETY: the caller must guarantee that `src` is valid for reads.
@@ -784,7 +785,8 @@ pub unsafe fn read<T>(src: *const T) -> T {
784785
/// ```
785786
#[inline]
786787
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
787-
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
788+
#[rustc_const_unstable(feature = "const_ptr_read", issue = "none")]
789+
pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
788790
// `copy_nonoverlapping` takes care of debug_assert.
789791
let mut tmp = MaybeUninit::<T>::uninit();
790792
// SAFETY: the caller must guarantee that `src` is valid for reads.

0 commit comments

Comments
 (0)