-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Tracking issue for UnsafeCell::raw_get
#66358
Comments
Would it work to have it be a method by adding additional implementations on impl<T: ?Sized> *mut UnsafeCell<T> {
pub const fn raw_get(self) -> *mut T {
UnsafeCell::raw_get(self)
}
}
impl<T: ?Sized> *const UnsafeCell<T> {
pub const fn raw_get(self) -> *mut T {
UnsafeCell::raw_get(self)
}
} |
@RalfJung Is there an option to stabilize the associated function first and open a separate tracking issue for the method impl? I read the discussion at #66248 (comment) and it sounded like the associated function would be forward compatible with any future implementation as a method, unless I misunderstood. |
@DavidVonDerau that's up to @rust-lang/libs, really -- I don't know if this is definitely forward compatible or not (though it seems plausible). Also, don't have have stable functions with |
Cc @rust-lang/libs (I had a typo in the ping above, don't know if GH sends notifications for pings in edits) |
@rust-lang/libs-api: I am proposing to stabilize the UnsafeCell::raw_get associated function as currently implemented in nightly: impl<T: ?Sized> UnsafeCell<T> {
pub const fn raw_get(this: *const Self) -> *mut T;
} At the call site, use of this associated function looks like: let m = MaybeUninit::<UnsafeCell<i32>>::uninit();
unsafe { UnsafeCell::raw_get(m.as_ptr()).write(5); }
let uc = unsafe { m.assume_init() }; In response to the unresolved issue that method syntax would be cleaner at the call site, apparently this use case is already covered by #44874. We can backward compatibly replace Demo: #![feature(arbitrary_self_types)]
use std::mem::MaybeUninit;
struct UnsafeCell;
struct T;
impl UnsafeCell {
fn raw_get(self: *const Self) -> *mut T { unimplemented!() }
}
fn main() {
let m = MaybeUninit::<UnsafeCell>::uninit();
unsafe { m.as_ptr().raw_get().write(T) }
let _uc = unsafe { m.assume_init() };
} |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
To me, it feels surprising that the name is |
I don't have a strong opinion on it. But I suppose the 'raw' applies to the @rust-lang/libs-api Any opinions on |
Spitballing other names:
Not a huge fan of any of them (including |
One more thing: we have |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
Note that the existing
Doesn't look like it.
As @dtolnay pointed out during the libs api meeting last week: |
Aha, now that clicked for me! What we are emphasizing here is that self is a raw pointer: |
#66248 added a raw pointer variant of
UnsafeCell::get
.Unresolved issues:
m.as_ptr().raw_get().write(5)
is so much more readable thanUnsafeCell::raw_get(m.as_ptr()).write(5)
. Also see add raw ptr variant of UnsafeCell::get #66248 (comment).The text was updated successfully, but these errors were encountered: