Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Dec 22, 2024

  • Implementing PointerLike for UnsafeCell enables the possibility of interior mutable dyn* values. Since this means potentially exercising new codegen behavior, I added a test for it in tests/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 for Atomic* types, since they are not repr(transparent) (and, in theory if not in practice, AtomicUsize's alignment may be greater than that of an ordinary pointer or usize).

  • Implementing PointerLike for NonNull is useful for pointer types which wrap NonNull.

  • Implementing PointerLike for isize 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)

`PointerLike` is already implemented for raw pointers and `usize`,
so this should be straightforward.
@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. F-dyn_star `#![feature(dyn_star)]` labels Dec 22, 2024
@rust-log-analyzer

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> {}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-dyn_star `#![feature(dyn_star)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants