8000 make MaybeUninit::as_(mut_)ptr const by RalfJung · Pull Request #75250 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

make MaybeUninit::as_(mut_)ptr const #75250

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

Merged
merged 2 commits into from
Aug 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make MaybeUninit::as_(mut_)ptr const
  • Loading branch information
RalfJung committed Aug 7, 2020
commit 0aee186723a3bb3290fd4348b92b3c1aad862fc9
12 changes: 8 additions & 4 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ impl<T> MaybeUninit<T> {
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
/// until they are, it is advisable to avoid them.)
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")]
#[inline(always)]
pub fn as_ptr(&self) -> *const T {
unsafe { &*self.value as *const T }
pub const fn as_ptr(&self) -> *const T {
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
self as *const _ as *const T
}

/// Gets a mutable pointer to the contained value. Reading from this pointer or turning it
Expand Down Expand Up @@ -442,9 +444,11 @@ impl<T> MaybeUninit<T> {
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
/// until they are, it is advisable to avoid them.)
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")]
#[inline(always)]
pub fn as_mut_ptr(&mut self) -> *mut T {
unsafe { &mut *self.value as *mut T }
pub const fn as_mut_ptr(&mut self) -> *mut T {
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
self as *mut _ as *mut T
}

/// Extracts the value from the `MaybeUninit<T>` container. This is a great way
Expand Down
0