about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-08-10 18:46:21 +0000
committerbors <bors@rust-lang.org>2015-08-10 18:46:21 +0000
commit3d69bec88119e0471a98cd2075fcf53c43ebca3e (patch)
treeb84fecb519b6883f4d75d521a90f9d476782e4cb /src/libcoretest
parent96a1f40402cdd05d29d1f1c0b62001254db8dcf6 (diff)
parent33af24ca4c2a6edaed0509a5b9ac3fde964a2847 (diff)
downloadrust-3d69bec88119e0471a98cd2075fcf53c43ebca3e.tar.gz
rust-3d69bec88119e0471a98cd2075fcf53c43ebca3e.zip
Auto merge of #27252 - tbu-:pr_less_transmutes, r=alexcrichton
The replacements are functions that usually use a single `mem::transmute` in their body and restrict input and output via more concrete types than `T` and `U`. Worth noting are the `transmute` functions for slices and the `from_utf8*` family for mutable slices. Additionally, `mem::transmute` was often used for casting raw pointers, when you can already cast raw pointers just fine with `as`.

This builds upon #27233.
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/hash/mod.rs13
-rw-r--r--src/libcoretest/ptr.rs3
2 files changed, 5 insertions, 11 deletions
diff --git a/src/libcoretest/hash/mod.rs b/src/libcoretest/hash/mod.rs
index 697c3ee254b..595bce68201 100644
--- a/src/libcoretest/hash/mod.rs
+++ b/src/libcoretest/hash/mod.rs
@@ -10,7 +10,6 @@
 
 mod sip;
 
-use std::mem;
 use std::hash::{Hash, Hasher};
 use std::default::Default;
 
@@ -72,15 +71,11 @@ fn test_writer_hasher() {
 
     // FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]>
 
-    unsafe {
-        let ptr: *const i32 = mem::transmute(5_usize);
-        assert_eq!(hash(&ptr), 5);
-    }
+    let ptr = 5_usize as *const i32;
+    assert_eq!(hash(&ptr), 5);
 
-    unsafe {
-        let ptr: *mut i32 = mem::transmute(5_usize);
-        assert_eq!(hash(&ptr), 5);
-    }
+    let ptr = 5_usize as *mut i32;
+    assert_eq!(hash(&ptr), 5);
 }
 
 struct Custom { hash: u64 }
diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs
index 865b049aae5..343db93d4a9 100644
--- a/src/libcoretest/ptr.rs
+++ b/src/libcoretest/ptr.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use core::ptr::*;
-use core::mem;
 
 #[test]
 fn test() {
@@ -20,7 +19,7 @@ fn test() {
         };
         let mut p = Pair {fst: 10, snd: 20};
         let pptr: *mut Pair = &mut p;
-        let iptr: *mut isize = mem::transmute(pptr);
+        let iptr: *mut isize = pptr as *mut isize;
         assert_eq!(*iptr, 10);
         *iptr = 30;
         assert_eq!(*iptr, 30);