rust/tests/ui/self
Matthias Krüger e0d71f500c
Rollup merge of #97373 - dimpolo:cell_dispatch_from_dyn, r=dtolnay
impl DispatchFromDyn for Cell and UnsafeCell

After some fruitful discussion on [Internals](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell-2/16520) here's my first PR to rust-lang/rust 🎉

Please let me know if there's something I missed.

This adds `DispatchFromDyn` impls for `Cell`, `UnsafeCell` and `SyncUnsafeCell`.
An existing test is also expanded to test the `Cell` impl (which requires the `UnsafeCell` impl)

The different `RefCell` types can not implement `DispatchFromDyn` since they have more than one (non ZST) field.

 

**Edit:**
### What:
These changes allow one to make types like `MyRc`(code below), to be object safe method receivers after implementing `DispatchFromDyn` and `Deref` for them.

This allows for code like this:
```rust
struct MyRc<T: ?Sized>(Cell<NonNull<RcBox<T>>>);

/* impls for DispatchFromDyn, CoerceUnsized and Deref for MyRc*/

trait Trait {
    fn foo(self: MyRc<Self>);
}

let impls_trait = ...;
let rc = MyRc::new(impls_trait) as MyRc<dyn Trait>;
rc.foo();
```

Note: `Cell` and `UnsafeCell` won't directly become valid method receivers since they don't implement `Deref`. Making use of these changes requires a wrapper type and nightly features.

### Why:
A custom pointer type with interior mutability allows one to store extra information in the pointer itself.
These changes allow for such a type to be a method receiver.

### Examples:
My use case is a cycle aware custom `Rc` implementation that when dropping a cycle marks some references dangling.

On the [forum](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell/14762/8) andersk mentioned that they track if a `Gc` reference is rooted with an extra bit in the reference itself.
2023-01-26 07:53:21 +01:00
..
auxiliary
elision
arbitrary_self_types_nested.rs
arbitrary_self_types_pin_lifetime_impl_trait-async.rs
arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
arbitrary_self_types_pin_lifetime_impl_trait.rs
arbitrary_self_types_pin_lifetime_impl_trait.stderr
arbitrary_self_types_pin_lifetime_mismatch-async.rs
arbitrary_self_types_pin_lifetime_mismatch-async.stderr
arbitrary_self_types_pin_lifetime_mismatch.rs
arbitrary_self_types_pin_lifetime_mismatch.stderr
arbitrary_self_types_pin_lifetime-async.rs
arbitrary_self_types_pin_lifetime.rs
arbitrary_self_types_pointers_and_wrappers.rs impl DispatchFromDyn for Cell and UnsafeCell 2023-01-24 12:06:12 +01:00
arbitrary_self_types_raw_pointer_struct.rs
arbitrary_self_types_raw_pointer_trait.rs
arbitrary_self_types_silly.rs
arbitrary_self_types_stdlib_pointers.rs
arbitrary_self_types_struct.rs
arbitrary_self_types_trait.rs
arbitrary_self_types_unsized_struct.rs
arbitrary-self-types-not-object-safe.curr.stderr
arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr
arbitrary-self-types-not-object-safe.rs
builtin-superkinds-self-type.rs
by-value-self-in-mut-slot.rs
class-missing-self.rs
class-missing-self.stderr
explicit_self_xcrate_exe.rs
explicit-self-closures.rs
explicit-self-generic.rs
explicit-self-objects-uniq.rs
explicit-self.rs
issue-61882-2.rs
issue-61882-2.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
issue-61882.rs
issue-61882.stderr
move-self.rs
object-safety-sized-self-by-value-self.rs
object-safety-sized-self-generic-method.rs
object-safety-sized-self-return-Self.rs
objects-owned-object-owned-method.rs
point-at-arbitrary-self-type-method.rs
point-at-arbitrary-self-type-method.stderr
point-at-arbitrary-self-type-trait-method.rs
point-at-arbitrary-self-type-trait-method.stderr
self_lifetime-async.rs
self_lifetime.rs
self_type_keyword-2.rs
self_type_keyword-2.stderr
self_type_keyword.rs
self_type_keyword.stderr
self-impl-2.rs
self-impl.rs
self-impl.stderr
self-in-mut-slot-default-method.rs
self-in-mut-slot-immediate-value.rs
self-in-typedefs.rs
self-infer.rs
self-infer.stderr
self-re-assign.rs
self-shadowing-import.rs
self-type-param.rs
self-vs-path-ambiguity.rs
self-vs-path-ambiguity.stderr
string-self-append.rs
suggest-self-2.rs
suggest-self-2.stderr
suggest-self.rs
suggest-self.stderr
ufcs-explicit-self.rs
uniq-self-in-mut-slot.rs
where-for-self.rs