diff options
| author | Ralf Jung <post@ralfj.de> | 2018-11-22 08:55:17 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-12-07 09:20:54 +0100 |
| commit | 21b5950cf92a978f88dd65f408382637b60c52b5 (patch) | |
| tree | bfa4e03f53d010486ad8e34a91f07a1f93370032 | |
| parent | a2fb99bc17527798aeeef1d7ccc61811a9362131 (diff) | |
| download | rust-21b5950cf92a978f88dd65f408382637b60c52b5.tar.gz rust-21b5950cf92a978f88dd65f408382637b60c52b5.zip | |
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
| -rw-r--r-- | src/libcore/ptr.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 0387708033b..452f7a62f4b 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2815,14 +2815,14 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> { #[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 @@ impl<T: ?Sized> From<Unique<T>> for NonNull<T> { 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 @@ impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> { 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) } } } } |
