-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stabilize Rc
, Arc
and Pin
as method receivers
#55880
Conversation
This introduces a new trait `Receiver`, which requires `Self: Deref`. If the `arbitrary_self_types` feature is not enabled, then in `check_method_receiver` we require not only that the receiver type transitively derefs to `Self`, but also that each type in the deref chain implements `Receiver` in addition to `Deref`. By keeping the `Receiver` trait unstable, we ensure that only receiver types from the standard library can be used in stable Rust. This allows the following to be used as the type of `self`, without a feature flag: - `Self`, `&Self`, `&mut Self`, `Box<Self>` (already allowed) - `Rc<Self>`, `Arc<Self>` - `Pin<&Self>`, `Pin<&mut Self>`, etc. - any combination of the above, e.g. `Box<Rc<Self>>`, `Pin<Pin<Pin<&mut Self>>>`
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
I just realized how we can avoid stabilizing This would still allow Closing this in favour of that approach. |
I just saw that the the futures RFC has a method taking |
Blocked on FCP in #55786. |
We don't need the composition, because |
@withoutboats btw; do we need the extra FCP here? ISTM that the FCP in #55786 should be sufficient? |
we don't |
Triage, @withoutboats: should be good to review now since FCP is ~finished (or hours from it...) :) |
The only thing is this allows composed receivers, which wasn't included in that FCP. I've been working on another branch that only allows receivers that directly deref to |
ping from triage @withoutboats awaiting your review |
no need to review this, the replacement PR that doesn't include composed receivers should be up soon |
I still don't understand why composed receivers are being removed-- was there any motivation cited for this? (I asked the same in #55786 (comment)) |
@withoutboats I'm not sure which comment you are referring to, so can't clarify what I meant. But I think my issue with stabilizing composed receivers was that they seemed like something that could be controversial, at least more so than |
I've opened #56805 as a replacement to this. It allows everything that this PR allows, except for composed receivers. It also includes a bit of a refactor of |
…akis Stabilize `Rc`, `Arc` and `Pin` as method receivers Replaces #55880 Closes #55786 r? @nikomatsakis cc @withoutboats @cramertj 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.
This introduces a new
Receiver
trait, which requiresSelf: Deref
. If thearbitrary_self_types
feature is not enabled, then incheck_method_receiver
we require not only that the receiver type transitively derefs toSelf
, but also that each type in the deref chain implementsReceiver
in addition toDeref
.By keeping the
Receiver
trait unstable, we ensure that only receiver types from the standard library can be used in stable Rust.This allows the following to be used as the type of
self
, without a feature flag:Self
,&Self
,&mut Self
,Box<Self>
(already allowed)Rc<Self>
,Arc<Self>
Pin<&Self>
,Pin<&mut Self>
, etc.&Box<Rc<Self>>
,Pin<Pin<Pin<&mut Self>>>
An FCP is required here to stabilize
Rc
andArc
as receiver types. As a more conservative approach, we could remove theimpl
s ofReceiver
forRc
andArc
for now, and add them back later pending an RFC. We would still allowPin
to be used as a receiver type without a feature flag, but that wouldn't be a stabilization becausePin
still requires thepin
feature. EDIT: An FCP would still be required because we would be allowing things like&&Self
.cc #44874 #55786