about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-23 21:33:45 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-23 21:56:23 +0200
commit5b3016134fef93d9bed343bb15da837acf50b635 (patch)
treee2d20f0b6e70b9c46ecb34399e0426d009cc2ec9
parented97b421059d25a86b2f947734a8ae366b68f473 (diff)
downloadrust-5b3016134fef93d9bed343bb15da837acf50b635.tar.gz
rust-5b3016134fef93d9bed343bb15da837acf50b635.zip
use array::from_ref for slices
-rw-r--r--library/core/src/slice/raw.rs13
1 files changed, 3 insertions, 10 deletions
diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs
index a5811c5e472..09209306c9d 100644
--- a/library/core/src/slice/raw.rs
+++ b/library/core/src/slice/raw.rs
@@ -1,5 +1,6 @@
 //! Free functions to create `&[T]` and `&mut [T]`.
 
+use crate::array;
 use crate::intrinsics::is_aligned_and_not_null;
 use crate::mem;
 use crate::ptr;
@@ -140,19 +141,11 @@ pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T]
 /// Converts a reference to T into a slice of length 1 (without copying).
 #[stable(feature = "from_ref", since = "1.28.0")]
 pub fn from_ref<T>(s: &T) -> &[T] {
-    // SAFETY: a reference is guaranteed to be valid for reads. The returned
-    // reference cannot be mutated as it is an immutable reference.
-    // `mem::size_of::<T>()` cannot be larger than `isize::MAX`.
-    // Thus the call to `from_raw_parts` is safe.
-    unsafe { from_raw_parts(s, 1) }
+    array::from_ref(s)
 }
 
 /// Converts a reference to T into a slice of length 1 (without copying).
 #[stable(feature = "from_ref", since = "1.28.0")]
 pub fn from_mut<T>(s: &mut T) -> &mut [T] {
-    // SAFETY: a mutable reference is guaranteed to be valid for writes.
-    // The reference cannot be accessed by another pointer as it is an mutable reference.
-    // `mem::size_of::<T>()` cannot be larger than `isize::MAX`.
-    // Thus the call to `from_raw_parts_mut` is safe.
-    unsafe { from_raw_parts_mut(s, 1) }
+    array::from_mut(s)
 }