about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlbin Hedman <albin9604@gmail.com>2020-12-26 02:25:08 +0100
committerAlbin Hedman <albin9604@gmail.com>2020-12-26 02:25:08 +0100
commit7594d2a0843e2354d3046951b333604969fec2bc (patch)
treec90c1854fad99e1fb2d4e5eda3e7d8e19a79037d
parent1b77f8e6ead5f717e9f7889885c6e84e05f4cef2 (diff)
downloadrust-7594d2a0843e2354d3046951b333604969fec2bc.tar.gz
rust-7594d2a0843e2354d3046951b333604969fec2bc.zip
Constify ptr::read and ptr::read_unaligned
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/ptr/mod.rs6
2 files changed, 5 insertions, 2 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 5b19bf6b80f..acf4936ee08 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -73,6 +73,7 @@
 #![feature(const_assert_type)]
 #![feature(const_discriminant)]
 #![feature(const_cell_into_inner)]
+#![feature(const_intrinsic_copy)]
 #![feature(const_checked_int_methods)]
 #![feature(const_euclidean_int_methods)]
 #![feature(const_float_classify)]
diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs
index 27d49529a5e..14d6695a0f3 100644
--- a/library/core/src/ptr/mod.rs
+++ b/library/core/src/ptr/mod.rs
@@ -685,7 +685,8 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
 /// [valid]: self#safety
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
-pub unsafe fn read<T>(src: *const T) -> T {
+#[rustc_const_unstable(feature = "const_ptr_read", issue = "none")]
+pub const unsafe fn read<T>(src: *const T) -> T {
     // `copy_nonoverlapping` takes care of debug_assert.
     let mut tmp = MaybeUninit::<T>::uninit();
     // SAFETY: the caller must guarantee that `src` is valid for reads.
@@ -784,7 +785,8 @@ pub unsafe fn read<T>(src: *const T) -> T {
 /// ```
 #[inline]
 #[stable(feature = "ptr_unaligned", since = "1.17.0")]
-pub unsafe fn read_unaligned<T>(src: *const T) -> T {
+#[rustc_const_unstable(feature = "const_ptr_read", issue = "none")]
+pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
     // `copy_nonoverlapping` takes care of debug_assert.
     let mut tmp = MaybeUninit::<T>::uninit();
     // SAFETY: the caller must guarantee that `src` is valid for reads.