about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-09-17 14:09:48 +0900
committerGitHub <noreply@github.com>2021-09-17 14:09:48 +0900
commit5d14396ed0b8efc06e3446bd3a6ed2c3e8eccd80 (patch)
tree4073f44f464551649077abfbd609413a29bd229f
parent5e910373f14880161ca22f7ce825048ffba1ab78 (diff)
parent349ac4f6c8839c89a39d1dd9fac1fbe9a30f2626 (diff)
downloadrust-5d14396ed0b8efc06e3446bd3a6ed2c3e8eccd80.tar.gz
rust-5d14396ed0b8efc06e3446bd3a6ed2c3e8eccd80.zip
Rollup merge of #88887 - fee1-dead:const-deref, r=oli-obk
Const Deref

Implements `const Deref`/`const DerefMut` for `&mut T`, `&T`, `Cow<'_, B>` and `ManuallyDrop<T>`
-rw-r--r--library/alloc/src/borrow.rs6
-rw-r--r--library/core/src/mem/manually_drop.rs6
-rw-r--r--library/core/src/ops/deref.rs6
3 files changed, 13 insertions, 5 deletions
diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs
index 482a497201d..9ecbf058231 100644
--- a/library/alloc/src/borrow.rs
+++ b/library/alloc/src/borrow.rs
@@ -330,7 +330,11 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
+#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
+impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
+where
+    B::Owned: ~const Borrow<B>,
+{
     type Target = B;
 
     fn deref(&self) -> &B {
diff --git a/library/core/src/mem/manually_drop.rs b/library/core/src/mem/manually_drop.rs
index d86939454be..20b6453990d 100644
--- a/library/core/src/mem/manually_drop.rs
+++ b/library/core/src/mem/manually_drop.rs
@@ -145,7 +145,8 @@ impl<T: ?Sized> ManuallyDrop<T> {
 }
 
 #[stable(feature = "manually_drop", since = "1.20.0")]
-impl<T: ?Sized> Deref for ManuallyDrop<T> {
+#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
+impl<T: ?Sized> const Deref for ManuallyDrop<T> {
     type Target = T;
     #[inline(always)]
     fn deref(&self) -> &T {
@@ -154,7 +155,8 @@ impl<T: ?Sized> Deref for ManuallyDrop<T> {
 }
 
 #[stable(feature = "manually_drop", since = "1.20.0")]
-impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
+#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
+impl<T: ?Sized> const DerefMut for ManuallyDrop<T> {
     #[inline(always)]
     fn deref_mut(&mut self) -> &mut T {
         &mut self.value
diff --git a/library/core/src/ops/deref.rs b/library/core/src/ops/deref.rs
index dcf3ce070ec..fb4ec83bc28 100644
--- a/library/core/src/ops/deref.rs
+++ b/library/core/src/ops/deref.rs
@@ -76,7 +76,8 @@ pub trait Deref {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: ?Sized> Deref for &T {
+#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
+impl<T: ?Sized> const Deref for &T {
     type Target = T;
 
     #[rustc_diagnostic_item = "noop_method_deref"]
@@ -89,7 +90,8 @@ impl<T: ?Sized> Deref for &T {
 impl<T: ?Sized> !DerefMut for &T {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: ?Sized> Deref for &mut T {
+#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
+impl<T: ?Sized> const Deref for &mut T {
     type Target = T;
 
     fn deref(&self) -> &T {