]> git.lizzy.rs Git - rust.git/commitdiff
Remove unnecessary explicit conversions to *const T
authorwe <vadim.petrochenkov@gmail.com>
Sat, 17 Jan 2015 04:34:10 +0000 (07:34 +0300)
committerwe <vadim.petrochenkov@gmail.com>
Sat, 17 Jan 2015 04:34:10 +0000 (07:34 +0300)
14 files changed:
src/doc/trpl/unsafe.md
src/liballoc/heap.rs
src/libcollections/btree/node.rs
src/libcollections/ring_buf.rs
src/libcollections/slice.rs
src/libcollections/vec.rs
src/libcore/atomic.rs
src/libcore/ptr.rs
src/libcore/slice.rs
src/librustc_trans/trans/builder.rs
src/librustdoc/flock.rs
src/libstd/collections/hash/table.rs
src/libstd/sys/unix/backtrace.rs
src/libstd/thread_local/mod.rs

index 075340660df154611e042fcdf34abe51df93251d..997dda98ef369bf1b90c1462f1baaa99fa0d448a 100644 (file)
@@ -254,7 +254,7 @@ impl<T: Send> Drop for Unique<T> {
             // Copy the object out from the pointer onto the stack,
             // where it is covered by normal Rust destructor semantics
             // and cleans itself up, if necessary
-            ptr::read(self.ptr as *const T);
+            ptr::read(self.ptr);
 
             // clean-up our allocation
             free(self.ptr as *mut c_void)
index b7bc1b4764614ac50e6f9fd32384e812ca1bbc2e..bd5b43b782e8d67ecddc7fde67efd874c95e57a3 100644 (file)
@@ -298,7 +298,7 @@ pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint)
             libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
         } else {
             let new_ptr = allocate(size, align);
-            ptr::copy_memory(new_ptr, ptr as *const u8, cmp::min(size, old_size));
+            ptr::copy_memory(new_ptr, ptr, cmp::min(size, old_size));
             deallocate(ptr, old_size, align);
             new_ptr
         }
index 7d5422290e25ad1493728a8ee646962fef94ddbf..19c48f88caa5cb8272fdd5333cf044276abd4310 100644 (file)
@@ -326,11 +326,11 @@ unsafe fn destroy(&mut self) {
     pub fn as_slices<'a>(&'a self) -> (&'a [K], &'a [V]) {
         unsafe {(
             mem::transmute(raw::Slice {
-                data: self.keys.0 as *const K,
+                data: self.keys.0,
                 len: self.len()
             }),
             mem::transmute(raw::Slice {
-                data: self.vals.0 as *const V,
+                data: self.vals.0,
                 len: self.len()
             })
         )}
@@ -349,7 +349,7 @@ pub fn as_slices_internal<'a>(&'a self) -> (&'a [K], &'a [V], &'a [Node<K, V>])
         } else {
             unsafe {
                 mem::transmute(raw::Slice {
-                    data: self.edges.0 as *const Node<K, V>,
+                    data: self.edges.0,
                     len: self.len() + 1
                 })
             }
index c3d226758683767deaba45e4811692744076fbae..b9cb4be7c1891caf463650eeabb524c32952f98b 100644 (file)
@@ -88,19 +88,19 @@ impl<T> RingBuf<T> {
     /// Turn ptr into a slice
     #[inline]
     unsafe fn buffer_as_slice(&self) -> &[T] {
-        mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap })
+        mem::transmute(RawSlice { data: self.ptr, len: self.cap })
     }
 
     /// Turn ptr into a mut slice
     #[inline]
     unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] {
-        mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap })
+        mem::transmute(RawSlice { data: self.ptr, len: self.cap })
     }
 
     /// Moves an element out of the buffer
     #[inline]
     unsafe fn buffer_read(&mut self, off: uint) -> T {
-        ptr::read(self.ptr.offset(off as int) as *const T)
+        ptr::read(self.ptr.offset(off as int))
     }
 
     /// Writes an element into the buffer, moving it.
index 4812ecc2c0b754b7a3a83b58dd1f43446271b495..988ec4c661faae229e2951dea5effe788c05d686 100644 (file)
@@ -1222,7 +1222,7 @@ fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> O
                                  &*buf_v.offset(j),
                                  (i - j) as uint);
                 ptr::copy_nonoverlapping_memory(buf_v.offset(j),
-                                                &tmp as *const T,
+                                                &tmp,
                                                 1);
                 mem::forget(tmp);
             }
index 73afefc5a03317c5281a52c8a25a9861f700d031..adc7ce8f07214b5814c7ae7f7462151f96f2ae60 100644 (file)
@@ -426,7 +426,7 @@ pub fn truncate(&mut self, len: uint) {
     pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
         unsafe {
             mem::transmute(RawSlice {
-                data: *self.ptr as *const T,
+                data: *self.ptr,
                 len: self.len,
             })
         }
@@ -574,7 +574,7 @@ pub fn remove(&mut self, index: uint) -> T {
                 let ptr = self.as_mut_ptr().offset(index as int);
                 // copy it out, unsafely having a copy of the value on
                 // the stack and in the vector at the same time.
-                ret = ptr::read(ptr as *const T);
+                ret = ptr::read(ptr);
 
                 // Shift everything down to fill in that spot.
                 ptr::copy_memory(ptr, &*ptr.offset(1), len - index - 1);
@@ -842,7 +842,7 @@ pub fn map_in_place<U, F>(self, mut f: F) -> Vec<U> where F: FnMut(T) -> U {
                     //          |         |
                     //          end_u     end_t
 
-                    let t = ptr::read(pv.start_t as *const T);
+                    let t = ptr::read(pv.start_t);
                     //  start_u start_t
                     //  |       |
                     // +-+-+-+-+-+-+-+-+-+
@@ -1414,7 +1414,7 @@ impl<T> AsSlice<T> for Vec<T> {
     fn as_slice<'a>(&'a self) -> &'a [T] {
         unsafe {
             mem::transmute(RawSlice {
-                data: *self.ptr as *const T,
+                data: *self.ptr,
                 len: self.len
             })
         }
@@ -1777,11 +1777,11 @@ fn drop(&mut self) {
 
             // We have instances of `U`s and `T`s in `vec`. Destruct them.
             while self.start_u != self.end_u {
-                let _ = ptr::read(self.start_u as *const U); // Run a `U` destructor.
+                let _ = ptr::read(self.start_u); // Run a `U` destructor.
                 self.start_u = self.start_u.offset(1);
             }
             while self.start_t != self.end_t {
-                let _ = ptr::read(self.start_t as *const T); // Run a `T` destructor.
+                let _ = ptr::read(self.start_t); // Run a `T` destructor.
                 self.start_t = self.start_t.offset(1);
             }
             // After this destructor ran, the destructor of `vec` will run,
index aa93d9ed8379230e1eb5dc9c7baa4d3ae962a772..18f7fff9053ceb00a398ec0727a77eabcf7f7658 100644 (file)
@@ -199,7 +199,7 @@ pub fn new(v: bool) -> AtomicBool {
     #[inline]
     #[stable]
     pub fn load(&self, order: Ordering) -> bool {
-        unsafe { atomic_load(self.v.get() as *const usize, order) > 0 }
+        unsafe { atomic_load(self.v.get(), order) > 0 }
     }
 
     /// Stores a value into the bool.
@@ -438,7 +438,7 @@ pub fn new(v: isize) -> AtomicIsize {
     /// ```
     #[inline]
     pub fn load(&self, order: Ordering) -> isize {
-        unsafe { atomic_load(self.v.get() as *const isize, order) }
+        unsafe { atomic_load(self.v.get(), order) }
     }
 
     /// Stores a value into the isize.
@@ -615,7 +615,7 @@ pub fn new(v: usize) -> AtomicUsize {
     /// ```
     #[inline]
     pub fn load(&self, order: Ordering) -> usize {
-        unsafe { atomic_load(self.v.get() as *const usize, order) }
+        unsafe { atomic_load(self.v.get(), order) }
     }
 
     /// Stores a value into the usize.
@@ -796,7 +796,7 @@ pub fn new(p: *mut T) -> AtomicPtr<T> {
     #[stable]
     pub fn load(&self, order: Ordering) -> *mut T {
         unsafe {
-            atomic_load(self.p.get() as *const *mut T, order) as *mut T
+            atomic_load(self.p.get(), order) as *mut T
         }
     }
 
@@ -1070,7 +1070,7 @@ pub fn new(v: int) -> AtomicInt {
 
     #[inline]
     pub fn load(&self, order: Ordering) -> int {
-        unsafe { atomic_load(self.v.get() as *const int, order) }
+        unsafe { atomic_load(self.v.get(), order) }
     }
 
     #[inline]
@@ -1123,7 +1123,7 @@ pub fn new(v: uint) -> AtomicUint {
 
     #[inline]
     pub fn load(&self, order: Ordering) -> uint {
-        unsafe { atomic_load(self.v.get() as *const uint, order) }
+        unsafe { atomic_load(self.v.get(), order) }
     }
 
     #[inline]
index baf998d0828a27c7f7818c0aca169ee91794ee0f..0b89467d63b83f2800ff34948a29a0574c801aa2 100644 (file)
@@ -329,7 +329,7 @@ fn is_null(self) -> bool { self as uint == 0 }
     #[inline]
     #[stable]
     unsafe fn offset(self, count: int) -> *mut T {
-        intrinsics::offset(self as *const T, count) as *mut T
+        intrinsics::offset(self, count) as *mut T
     }
 
     #[inline]
index 22da168911daad66f84a6bc6a731408cfbae17c0..50cbb7a61dce305ce393e1965be56f7436056ccb 100644 (file)
@@ -741,7 +741,7 @@ macro_rules! make_slice {
             diff / mem::size_of::<$t>()
         };
         unsafe {
-            transmute::<_, $result>(RawSlice { data: $start as *const T, len: len })
+            transmute::<_, $result>(RawSlice { data: $start, len: len })
         }
     }}
 }
@@ -1409,7 +1409,7 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
 #[inline]
 #[unstable = "should be renamed to from_raw_parts_mut"]
 pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
-    transmute(RawSlice { data: *p as *const T, len: len })
+    transmute(RawSlice { data: *p, len: len })
 }
 
 //
index 75194e3d21fcb57ac29602db0ed39d9e803159b3..2ad421103424022ad1f0f63bdd564f946ea4c50a 100644 (file)
@@ -33,7 +33,7 @@ pub struct Builder<'a, 'tcx: 'a> {
 // lot more efficient) than doing str::as_c_str("", ...) every time.
 pub fn noname() -> *const c_char {
     static CNULL: c_char = 0;
-    &CNULL as *const c_char
+    &CNULL
 }
 
 impl<'a, 'tcx> Builder<'a, 'tcx> {
index dcc90117d26606041d1cc721e52e893706df9c8d..b682723631d3fe58a87968756e1deab839a6022f 100644 (file)
@@ -126,7 +126,7 @@ pub fn new(p: &Path) -> Lock {
                 l_sysid: 0,
             };
             let ret = unsafe {
-                libc::fcntl(fd, os::F_SETLKW, &flock as *const os::flock)
+                libc::fcntl(fd, os::F_SETLKW, &flock)
             };
             if ret == -1 {
                 unsafe { libc::close(fd); }
@@ -147,7 +147,7 @@ fn drop(&mut self) {
                 l_sysid: 0,
             };
             unsafe {
-                libc::fcntl(self.fd, os::F_SETLK, &flock as *const os::flock);
+                libc::fcntl(self.fd, os::F_SETLK, &flock);
                 libc::close(self.fd);
             }
         }
index f28b95dbe95c4b64a605e434116c432693ae5aa2..d810460a7d497886ca628bbe074d26e654cc68d8 100644 (file)
@@ -395,9 +395,6 @@ impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> FullBucket<K, V, M> {
     /// This works similarly to `put`, building an `EmptyBucket` out of the
     /// taken bucket.
     pub fn take(mut self) -> (EmptyBucket<K, V, M>, K, V) {
-        let key = self.raw.key as *const K;
-        let val = self.raw.val as *const V;
-
         self.table.size -= 1;
 
         unsafe {
@@ -408,8 +405,8 @@ pub fn take(mut self) -> (EmptyBucket<K, V, M>, K, V) {
                     idx: self.idx,
                     table: self.table
                 },
-                ptr::read(key),
-                ptr::read(val)
+                ptr::read(self.raw.key),
+                ptr::read(self.raw.val)
             )
         }
     }
@@ -477,8 +474,8 @@ pub fn full(&self) -> &FullBucket<K, V, M> {
     pub fn shift(mut self) -> Option<GapThenFull<K, V, M>> {
         unsafe {
             *self.gap.raw.hash = mem::replace(&mut *self.full.raw.hash, EMPTY_BUCKET);
-            copy_nonoverlapping_memory(self.gap.raw.key, self.full.raw.key as *const K, 1);
-            copy_nonoverlapping_memory(self.gap.raw.val, self.full.raw.val as *const V, 1);
+            copy_nonoverlapping_memory(self.gap.raw.key, self.full.raw.key, 1);
+            copy_nonoverlapping_memory(self.gap.raw.val, self.full.raw.val, 1);
         }
 
         let FullBucket { raw: prev_raw, idx: prev_idx, .. } = self.full;
@@ -781,8 +778,8 @@ fn next(&mut self) -> Option<(K, V)> {
                 if *self.raw.hash != EMPTY_BUCKET {
                     self.elems_left -= 1;
                     return Some((
-                        ptr::read(self.raw.key as *const K),
-                        ptr::read(self.raw.val as *const V)
+                        ptr::read(self.raw.key),
+                        ptr::read(self.raw.val)
                     ));
                 }
             }
@@ -878,8 +875,8 @@ fn next(&mut self) -> Option<(SafeHash, K, V)> {
                     SafeHash {
                         hash: *bucket.hash,
                     },
-                    ptr::read(bucket.key as *const K),
-                    ptr::read(bucket.val as *const V)
+                    ptr::read(bucket.key),
+                    ptr::read(bucket.val)
                 )
             }
         })
@@ -906,8 +903,8 @@ fn next(&mut self) -> Option<(SafeHash, K, V)> {
                     SafeHash {
                         hash: ptr::replace(bucket.hash, EMPTY_BUCKET),
                     },
-                    ptr::read(bucket.key as *const K),
-                    ptr::read(bucket.val as *const V)
+                    ptr::read(bucket.key),
+                    ptr::read(bucket.val)
                 )
             }
         })
index 7164931c55acd0fea51d1ae90705753707282380..70b9c012b008a38905149265255e63840455eaa5 100644 (file)
@@ -229,7 +229,7 @@ fn dladdr(addr: *const libc::c_void,
     }
 
     let mut info: Dl_info = unsafe { intrinsics::init() };
-    if unsafe { dladdr(addr as *const libc::c_void, &mut info) == 0 } {
+    if unsafe { dladdr(addr, &mut info) == 0 } {
         output(w, idx,addr, None)
     } else {
         output(w, idx, addr, Some(unsafe {
index e7c4e4ccdfb88d0abd6e19daec1a0eff9d7dea9c..4c99cff34da65cba8ace81c1f800c29ff9f732da 100644 (file)
@@ -449,7 +449,7 @@ fn _tlv_atexit(dtor: unsafe extern fn(*mut u8),
         // destructor as running for this thread so calls to `get` will return
         // `None`.
         *(*ptr).dtor_running.get() = true;
-        ptr::read((*ptr).inner.get() as *const T);
+        ptr::read((*ptr).inner.get());
     }
 }