Files
rust/library/core/src
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
..
2022-10-29 09:23:12 +02:00
2022-12-28 09:18:42 -05:00
2022-12-15 03:55:21 +00:00
2022-12-20 15:01:37 +00:00
2023-01-06 13:20:58 +01:00
2022-12-13 18:08:35 +01:00
2022-12-28 09:18:43 -05:00
2023-01-16 21:26:03 +01:00
2022-11-20 10:28:14 +01:00
2022-12-12 16:22:01 -07:00
2023-01-12 02:28:38 +00:00
2022-12-28 09:18:43 -05:00
2022-11-06 17:21:21 -05:00
2022-11-04 20:06:18 -07:00
2023-01-07 15:44:38 -05:00
2022-12-28 09:18:43 -05:00
2023-01-14 18:26:38 +01:00
2022-11-06 17:11:02 -05:00
2022-11-09 09:52:04 +01:00