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 Move /src/test to /tests 2023-01-11 09:32:08 +00:00
elision Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_nested.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_impl_trait-async.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_impl_trait-async.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_impl_trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_impl_trait.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_mismatch-async.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_mismatch-async.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_mismatch.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime_mismatch.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime-async.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_pin_lifetime.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
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 Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_raw_pointer_trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_silly.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_stdlib_pointers.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary_self_types_unsized_struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary-self-types-not-object-safe.curr.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
arbitrary-self-types-not-object-safe.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
builtin-superkinds-self-type.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
by-value-self-in-mut-slot.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
class-missing-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
class-missing-self.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
explicit_self_xcrate_exe.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
explicit-self-closures.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
explicit-self-generic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
explicit-self-objects-uniq.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
explicit-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-61882-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-61882-2.stderr Tweak E0597 2023-01-15 19:46:20 +00:00
issue-61882.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-61882.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
move-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-sized-self-by-value-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-sized-self-generic-method.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
object-safety-sized-self-return-Self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
objects-owned-object-owned-method.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
point-at-arbitrary-self-type-method.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
point-at-arbitrary-self-type-method.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
point-at-arbitrary-self-type-trait-method.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
point-at-arbitrary-self-type-trait-method.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_lifetime-async.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_lifetime.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_type_keyword-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_type_keyword-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_type_keyword.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self_type_keyword.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-impl-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-impl.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-impl.stderr When suggesting writing a fully qualified path probe for appropriate types 2023-01-11 21:30:10 +00:00
self-in-mut-slot-default-method.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-in-mut-slot-immediate-value.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-in-typedefs.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-infer.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-infer.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-re-assign.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-shadowing-import.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-type-param.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-vs-path-ambiguity.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
self-vs-path-ambiguity.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
string-self-append.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suggest-self-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suggest-self-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suggest-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suggest-self.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ufcs-explicit-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
uniq-self-in-mut-slot.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
where-for-self.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00