-
Notifications
You must be signed in to change notification settings - Fork 13.6k
impl DispatchFromDyn for Cell and UnsafeCell #97373
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ use crate::cmp::Ordering; | |
use crate::fmt::{self, Debug, Display}; | ||
use crate::marker::{PhantomData, Unsize}; | ||
use crate::mem; | ||
use crate::ops::{CoerceUnsized, Deref, DerefMut}; | ||
use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn}; | ||
use crate::ptr::{self, NonNull}; | ||
|
||
mod lazy; | ||
|
@@ -571,6 +571,16 @@ impl<T: Default> Cell<T> { | |
#[unstable(feature = "coerce_unsized", issue = "18598")] | ||
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {} | ||
|
||
// Allow types that wrap `Cell` to also implement `DispatchFromDyn` | ||
// and become object safe method receivers. | ||
// Note that currently `Cell` itself cannot be a method receiver | ||
// because it does not implement Deref. | ||
// In other words: | ||
// `self: Cell<&Self>` won't work | ||
// `self: CellWrapper<Self>` becomes possible | ||
#[unstable(feature = "dispatch_from_dyn", issue = "none")] | ||
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {} | ||
|
||
impl<T> Cell<[T]> { | ||
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>` | ||
/// | ||
|
@@ -2078,6 +2088,16 @@ impl<T> const From<T> for UnsafeCell<T> { | |
#[unstable(feature = "coerce_unsized", issue = "18598")] | ||
impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {} | ||
|
||
// Allow types that wrap `UnsafeCell` to also implement `DispatchFromDyn` | ||
// and become object safe method receivers. | ||
// Note that currently `UnsafeCell` itself cannot be a method receiver | ||
// because it does not implement Deref. | ||
// In other words: | ||
// `self: UnsafeCell<&Self>` won't work | ||
// `self: UnsafeCellWrapper<Self>` becomes possible | ||
#[unstable(feature = "dispatch_from_dyn", issue = "none")] | ||
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {} | ||
|
||
/// [`UnsafeCell`], but [`Sync`]. | ||
/// | ||
/// This is just an `UnsafeCell`, except it implements `Sync` | ||
|
@@ -2169,6 +2189,17 @@ impl<T> const From<T> for SyncUnsafeCell<T> { | |
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")] | ||
impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {} | ||
|
||
// Allow types that wrap `SyncUnsafeCell` to also implement `DispatchFromDyn` | ||
// and become object safe method receivers. | ||
// Note that currently `SyncUnsafeCell` itself cannot be a method receiver | ||
// because it does not implement Deref. | ||
// In other words: | ||
// `self: SyncUnsafeCell<&Self>` won't work | ||
// `self: SyncUnsafeCellWrapper<Self>` becomes possible | ||
#[unstable(feature = "dispatch_from_dyn", issue = "none")] | ||
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a stray line here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this from the above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah there has been a longstanding feature request for unstable APIs to be able to be covered by multiple tracking issues / feature gates. For example if there's a I thought there was a feature request issue filed for this but I wasn't able to find it just now. The way this is written in the PR is the best we can currently do. |
||
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {} | ||
|
||
#[allow(unused)] | ||
fn assert_coerce_unsized( | ||
a: UnsafeCell<&i32>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably ought to point at an actual issue, rather than none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trait itself currently doesn't have an issue associated with it.
rust/library/core/src/ops/unsize.rs
Lines 115 to 119 in bed4ad6
We could associate the trait and it's usages with arbitrary_self_types but I'm not sure if that is desired or should be done in this PR.