summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-05-31 11:22:51 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-05-31 11:32:27 -0400
commit042618da7b70b30c910377860e7d5cb16001a6a6 (patch)
treea0287490792a9cc0d1dde960f52229fac96e3bea /src/libstd
parent29aba8033afa4cab0261c82d5a4eded4b79af656 (diff)
downloadrust-042618da7b70b30c910377860e7d5cb16001a6a6.tar.gz
rust-042618da7b70b30c910377860e7d5cb16001a6a6.zip
ptr: replace unnecessary unsafe code
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ptr.rs76
1 files changed, 18 insertions, 58 deletions
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs
index cdd99ee3603..ebc0a4b1e96 100644
--- a/src/libstd/ptr.rs
+++ b/src/libstd/ptr.rs
@@ -72,11 +72,11 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
 
 /// Create an unsafe null pointer
 #[inline(always)]
-pub fn null<T>() -> *T { unsafe { cast::transmute(0u) } }
+pub fn null<T>() -> *T { 0 as *T }
 
 /// Create an unsafe mutable null pointer
 #[inline(always)]
-pub fn mut_null<T>() -> *mut T { unsafe { cast::transmute(0u) } }
+pub fn mut_null<T>() -> *mut T { 0 as *mut T }
 
 /// Returns true if the pointer is equal to the null pointer.
 #[inline(always)]
@@ -237,48 +237,28 @@ pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
     src
 }
 
-/**
-  Transform a region pointer - &T - to an unsafe pointer - *T.
-  This is safe, but is implemented with an unsafe block due to
-  transmute.
-*/
+/// Transform a region pointer - &T - to an unsafe pointer - *T.
 #[inline(always)]
 pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
-    unsafe { cast::transmute(thing) }
+    thing as *T
 }
 
-/**
-  Transform a const region pointer - &const T - to a const unsafe pointer -
-  *const T. This is safe, but is implemented with an unsafe block due to
-  transmute.
-*/
+/// Transform a const region pointer - &const T - to a const unsafe pointer - *const T.
 #[inline(always)]
 pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
-    unsafe { cast::transmute(thing) }
+    thing as *const T
 }
 
-/**
-  Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
-  *mut T. This is safe, but is implemented with an unsafe block due to
-  transmute.
-*/
+/// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
 #[inline(always)]
 pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
-    unsafe { cast::transmute(thing) }
+    thing as *mut T
 }
 
-/**
-  Cast a region pointer - &T - to a uint.
-  This is safe, but is implemented with an unsafe block due to
-  transmute.
-
-  (I couldn't think of a cutesy name for this one.)
-*/
+/// Cast a region pointer - &T - to a uint.
 #[inline(always)]
 pub fn to_uint<T>(thing: &T) -> uint {
-    unsafe {
-        cast::transmute(thing)
-    }
+    thing as *T as uint
 }
 
 /// Determine if two borrowed pointers point to the same thing.
@@ -404,14 +384,10 @@ impl<T> Ptr<T> for *mut T {
 impl<T> Eq for *const T {
     #[inline(always)]
     fn eq(&self, other: &*const T) -> bool {
-        unsafe {
-            let a: uint = cast::transmute(*self);
-            let b: uint = cast::transmute(*other);
-            return a == b;
-        }
+        (*self as uint) == (*other as uint)
     }
     #[inline(always)]
-    fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
+    fn ne(&self, other: &*const T) -> bool { !self.eq(other) }
 }
 
 // Comparison for pointers
@@ -419,35 +395,19 @@ impl<T> Eq for *const T {
 impl<T> Ord for *const T {
     #[inline(always)]
     fn lt(&self, other: &*const T) -> bool {
-        unsafe {
-            let a: uint = cast::transmute(*self);
-            let b: uint = cast::transmute(*other);
-            return a < b;
-        }
+        (*self as uint) < (*other as uint)
     }
     #[inline(always)]
     fn le(&self, other: &*const T) -> bool {
-        unsafe {
-            let a: uint = cast::transmute(*self);
-            let b: uint = cast::transmute(*other);
-            return a <= b;
-        }
+        (*self as uint) <= (*other as uint)
     }
     #[inline(always)]
     fn ge(&self, other: &*const T) -> bool {
-        unsafe {
-            let a: uint = cast::transmute(*self);
-            let b: uint = cast::transmute(*other);
-            return a >= b;
-        }
+        (*self as uint) >= (*other as uint)
     }
     #[inline(always)]
     fn gt(&self, other: &*const T) -> bool {
-        unsafe {
-            let a: uint = cast::transmute(*self);
-            let b: uint = cast::transmute(*other);
-            return a > b;
-        }
+        (*self as uint) > (*other as uint)
     }
 }
 
@@ -456,11 +416,11 @@ impl<T> Ord for *const T {
 impl<'self,T:Eq> Eq for &'self T {
     #[inline(always)]
     fn eq(&self, other: & &'self T) -> bool {
-        return *(*self) == *(*other);
+        *(*self) == *(*other)
     }
     #[inline(always)]
     fn ne(&self, other: & &'self T) -> bool {
-        return *(*self) != *(*other);
+        *(*self) != *(*other)
     }
 }