]> git.lizzy.rs Git - rust.git/commit
Stabilize `Rc`, `Arc` and `Pin` as method receivers
authorMichael Hewson <michael@michaelhewson.ca>
Tue, 20 Nov 2018 16:50:50 +0000 (11:50 -0500)
committerMichael Hewson <michael@michaelhewson.ca>
Thu, 20 Dec 2018 06:14:01 +0000 (01:14 -0500)
commit153f5a7892274764256862692fa7e2c51474e5d0
tree3fed21b23ee956226e952cfd4000f86e0900dd23
parentdaa8792f17ad5484ec1e3b0b1e2557f8603219d0
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.
16 files changed:
src/liballoc/boxed.rs
src/liballoc/lib.rs
src/liballoc/rc.rs
src/liballoc/sync.rs
src/libcore/ops/deref.rs
src/libcore/ops/mod.rs
src/libcore/pin.rs
src/librustc/middle/lang_items.rs
src/librustc_typeck/check/wfcheck.rs
src/test/run-pass/arbitrary_self_types_stdlib_pointers.rs
src/test/ui/feature-gates/feature-gate-arbitrary-self-types.rs
src/test/ui/feature-gates/feature-gate-arbitrary-self-types.stderr
src/test/ui/feature-gates/feature-gate-arbitrary_self_types-raw-pointer.rs
src/test/ui/feature-gates/feature-gate-arbitrary_self_types-raw-pointer.stderr
src/test/ui/privacy/privacy1.rs
src/test/ui/privacy/privacy1.stderr