diff options
| author | Michael Hewson <michael@michaelhewson.ca> | 2018-11-20 11:50:50 -0500 |
|---|---|---|
| committer | Michael Hewson <michael@michaelhewson.ca> | 2018-12-20 01:14:01 -0500 |
| commit | 153f5a7892274764256862692fa7e2c51474e5d0 (patch) | |
| tree | 3fed21b23ee956226e952cfd4000f86e0900dd23 /src/liballoc | |
| parent | daa8792f17ad5484ec1e3b0b1e2557f8603219d0 (diff) | |
| download | rust-153f5a7892274764256862692fa7e2c51474e5d0.tar.gz rust-153f5a7892274764256862692fa7e2c51474e5d0.zip | |
Stabilize `Rc`, `Arc` and `Pin` as method receivers
This lets you write methods using `self: Rc<Self>`, `self: Arc<Self>`, `self: Pin<&mut Self>`, `self: Pin<Box<Self>`, and other combinations involving `Pin` and another stdlib receiver type, without needing the `arbitrary_self_types`. Other user-created receiver types can be used, but they still require the feature flag to use. This is implemented by introducing a new trait, `Receiver`, which the method receiver's type must implement if the `arbitrary_self_types` feature is not enabled. To keep composed receiver types such as `&Arc<Self>` unstable, the receiver type is also required to implement `Deref<Target=Self>` when the feature flag is not enabled. This lets you use `self: Rc<Self>` and `self: Arc<Self>` in stable Rust, which was not allowed previously. It was agreed that they would be stabilized in #55786. `self: Pin<&Self>` and other pinned receiver types do not require the `arbitrary_self_types` feature, but they cannot be used on stable because `Pin` still requires the `pin` feature.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 7 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/sync.rs | 5 |
4 files changed, 15 insertions, 3 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 83adcce5c74..f1581310b48 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -77,7 +77,9 @@ use core::iter::{Iterator, FromIterator, FusedIterator}; use core::marker::{Unpin, Unsize}; use core::mem; use core::pin::Pin; -use core::ops::{CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Generator, GeneratorState}; +use core::ops::{ + CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState +}; use core::ptr::{self, NonNull, Unique}; use core::task::{LocalWaker, Poll}; @@ -583,6 +585,9 @@ impl<T: ?Sized> DerefMut for Box<T> { } } +#[unstable(feature = "receiver_trait", issue = "0")] +impl<T: ?Sized> Receiver for Box<T> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<I: Iterator + ?Sized> Iterator for Box<I> { type Item = I::Item; diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index abacc62c856..e00e430fab6 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -104,6 +104,7 @@ #![feature(ptr_internals)] #![feature(ptr_offset_from)] #![feature(rustc_attrs)] +#![feature(receiver_trait)] #![feature(specialization)] #![feature(split_ascii_whitespace)] #![feature(staged_api)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 6769a70ddbe..3fc70f4ac37 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -253,7 +253,7 @@ use core::intrinsics::abort; use core::marker; use core::marker::{Unpin, Unsize, PhantomData}; use core::mem::{self, align_of_val, forget, size_of_val}; -use core::ops::Deref; +use core::ops::{Deref, Receiver}; use core::ops::{CoerceUnsized, DispatchFromDyn}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -813,6 +813,9 @@ impl<T: ?Sized> Deref for Rc<T> { } } +#[unstable(feature = "receiver_trait", issue = "0")] +impl<T: ?Sized> Receiver for Rc<T> {} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> { /// Drops the `Rc`. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index e596694fb9d..55737016608 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -24,7 +24,7 @@ use core::fmt; use core::cmp::Ordering; use core::intrinsics::abort; use core::mem::{self, align_of_val, size_of_val}; -use core::ops::Deref; +use core::ops::{Deref, Receiver}; use core::ops::{CoerceUnsized, DispatchFromDyn}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -767,6 +767,9 @@ impl<T: ?Sized> Deref for Arc<T> { } } +#[unstable(feature = "receiver_trait", issue = "0")] +impl<T: ?Sized> Receiver for Arc<T> {} + impl<T: Clone> Arc<T> { /// Makes a mutable reference into the given `Arc`. /// |
