Unique/NonNull::from: make sure we convert to raw pointers ASAP

By going through a shared reference, we share the destination as read-only, meaning we can read but not write with the raw pointers
This commit is contained in:
Ralf Jung 2018-11-22 08:55:17 +01:00
parent a2fb99bc17
commit 21b5950cf9

View File

@ -2815,14 +2815,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[unstable(feature = "ptr_internals", issue = "0")]
impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
fn from(reference: &'a mut T) -> Self {
Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
Unique { pointer: unsafe { NonZero(reference as *mut T) }, _marker: PhantomData }
}
}
#[unstable(feature = "ptr_internals", issue = "0")]
impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
fn from(reference: &'a T) -> Self {
Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
Unique { pointer: unsafe { NonZero(reference as *const T) }, _marker: PhantomData }
}
}
@ -3025,7 +3025,7 @@ fn from(unique: Unique<T>) -> Self {
impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> {
#[inline]
fn from(reference: &'a mut T) -> Self {
NonNull { pointer: unsafe { NonZero(reference as _) } }
NonNull { pointer: unsafe { NonZero(reference as *mut T) } }
}
}
@ -3033,6 +3033,6 @@ fn from(reference: &'a mut T) -> Self {
impl<'a, T: ?Sized> From<&'a T> for NonNull<T> {
#[inline]
fn from(reference: &'a T) -> Self {
NonNull { pointer: unsafe { NonZero(reference as _) } }
NonNull { pointer: unsafe { NonZero(reference as *const T) } }
}
}