-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement PointerLike
for isize
, NonNull
, Cell
, UnsafeCell
, and SyncUnsafeCell
.
#134642
base: master
Are you sure you want to change the base?
Conversation
`PointerLike` is already implemented for raw pointers and `usize`, so this should be straightforward.
This comment has been minimized.
This comment has been minimized.
@@ -2364,6 +2370,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell | |||
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")] | |||
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {} | |||
|
|||
#[unstable(feature = "pointer_like_trait", issue = "none")] | |||
impl<T: PointerLike> PointerLike for SyncUnsafeCell<T> {} |
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.
Why not put these with the rest of the impls in core::marker
?
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.
I did this because it is consistent with the existing code organization: impls of other marker traits for “primitive” types are in core::marker
and defined using marker_impls!
, and impls for library-defined types are next to those types. I’m not aware of a reason why PointerLike
should be organized differently than other marker trait impls.
In fact, reviewing the existing usage of marker_impls!
, I should probably put the impl for NonNull
inside core::ptr::non_null
instead of in the marker_impls!
to be even more consistent.
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.
Sure, would you like to change that too?
Implementing
PointerLike
forUnsafeCell
enables the possibility of interior mutabledyn*
values. Since this means potentially exercising new codegen behavior, I added a test for it intests/ui/dyn-star/cell.rs
. Please let me know if there are further sorts of tests that should be written, or other care that should be taken with this change.It is unfortunately not possible without compiler changes to implement
PointerLike
forAtomic*
types, since they are notrepr(transparent)
(and, in theory if not in practice,AtomicUsize
's alignment may be greater than that of an ordinary pointer orusize
).Implementing
PointerLike
forNonNull
is useful for pointer types which wrapNonNull
.Implementing
PointerLike
forisize
is just for completeness; I have no use cases in mind, but I cannot think of any reason not to do this.Tracking issue: Tracking issue for dyn-star #102425
@rustbot label +F-dyn_star
(there is no label or tracking issue for F-pointer_like_trait)