Skip to content

Commit 812ce6c

Browse files
committed
Remove unnecessary explicit conversions to *const T
1 parent 378fb58 commit 812ce6c

File tree

14 files changed

+39
-42
lines changed

14 files changed

+39
-42
lines changed

src/doc/trpl/unsafe.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<T: Send> Drop for Unique<T> {
254254
// Copy the object out from the pointer onto the stack,
255255
// where it is covered by normal Rust destructor semantics
256256
// and cleans itself up, if necessary
257-
ptr::read(self.ptr as *const T);
257+
ptr::read(self.ptr);
258258
259259
// clean-up our allocation
260260
free(self.ptr as *mut c_void)

src/liballoc/heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ mod imp {
298298
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
299299
} else {
300300
let new_ptr = allocate(size, align);
301-
ptr::copy_memory(new_ptr, ptr as *const u8, cmp::min(size, old_size));
301+
ptr::copy_memory(new_ptr, ptr, cmp::min(size, old_size));
302302
deallocate(ptr, old_size, align);
303303
new_ptr
304304
}

src/libcollections/btree/node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ impl<K, V> Node<K, V> {
326326
pub fn as_slices<'a>(&'a self) -> (&'a [K], &'a [V]) {
327327
unsafe {(
328328
mem::transmute(raw::Slice {
329-
data: self.keys.0 as *const K,
329+
data: self.keys.0,
330330
len: self.len()
331331
}),
332332
mem::transmute(raw::Slice {
333-
data: self.vals.0 as *const V,
333+
data: self.vals.0,
334334
len: self.len()
335335
})
336336
)}
@@ -349,7 +349,7 @@ impl<K, V> Node<K, V> {
349349
} else {
350350
unsafe {
351351
mem::transmute(raw::Slice {
352-
data: self.edges.0 as *const Node<K, V>,
352+
data: self.edges.0,
353353
len: self.len() + 1
354354
})
355355
}

src/libcollections/ring_buf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ impl<T> RingBuf<T> {
8888
/// Turn ptr into a slice
8989
#[inline]
9090
unsafe fn buffer_as_slice(&self) -> &[T] {
91-
mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap })
91+
mem::transmute(RawSlice { data: self.ptr, len: self.cap })
9292
}
9393

9494
/// Turn ptr into a mut slice
9595
#[inline]
9696
unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] {
97-
mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap })
97+
mem::transmute(RawSlice { data: self.ptr, len: self.cap })
9898
}
9999

100100
/// Moves an element out of the buffer
101101
#[inline]
102102
unsafe fn buffer_read(&mut self, off: uint) -> T {
103-
ptr::read(self.ptr.offset(off as int) as *const T)
103+
ptr::read(self.ptr.offset(off as int))
104104
}
105105

106106
/// Writes an element into the buffer, moving it.

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> O
12221222
&*buf_v.offset(j),
12231223
(i - j) as uint);
12241224
ptr::copy_nonoverlapping_memory(buf_v.offset(j),
1225-
&tmp as *const T,
1225+
&tmp,
12261226
1);
12271227
mem::forget(tmp);
12281228
}

src/libcollections/vec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<T> Vec<T> {
426426
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
427427
unsafe {
428428
mem::transmute(RawSlice {
429-
data: *self.ptr as *const T,
429+
data: *self.ptr,
430430
len: self.len,
431431
})
432432
}
@@ -574,7 +574,7 @@ impl<T> Vec<T> {
574574
let ptr = self.as_mut_ptr().offset(index as int);
575575
// copy it out, unsafely having a copy of the value on
576576
// the stack and in the vector at the same time.
577-
ret = ptr::read(ptr as *const T);
577+
ret = ptr::read(ptr);
578578

579579
// Shift everything down to fill in that spot.
580580
ptr::copy_memory(ptr, &*ptr.offset(1), len - index - 1);
@@ -842,7 +842,7 @@ impl<T> Vec<T> {
842842
// | |
843843
// end_u end_t
844844

845-
let t = ptr::read(pv.start_t as *const T);
845+
let t = ptr::read(pv.start_t);
846846
// start_u start_t
847847
// | |
848848
// +-+-+-+-+-+-+-+-+-+
@@ -1414,7 +1414,7 @@ impl<T> AsSlice<T> for Vec<T> {
14141414
fn as_slice<'a>(&'a self) -> &'a [T] {
14151415
unsafe {
14161416
mem::transmute(RawSlice {
1417-
data: *self.ptr as *const T,
1417+
data: *self.ptr,
14181418
len: self.len
14191419
})
14201420
}
@@ -1777,11 +1777,11 @@ impl<T,U> Drop for PartialVecNonZeroSized<T,U> {
17771777

17781778
// We have instances of `U`s and `T`s in `vec`. Destruct them.
17791779
while self.start_u != self.end_u {
1780-
let _ = ptr::read(self.start_u as *const U); // Run a `U` destructor.
1780+
let _ = ptr::read(self.start_u); // Run a `U` destructor.
17811781
self.start_u = self.start_u.offset(1);
17821782
}
17831783
while self.start_t != self.end_t {
1784-
let _ = ptr::read(self.start_t as *const T); // Run a `T` destructor.
1784+
let _ = ptr::read(self.start_t); // Run a `T` destructor.
17851785
self.start_t = self.start_t.offset(1);
17861786
}
17871787
// After this destructor ran, the destructor of `vec` will run,

src/libcore/atomic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl AtomicBool {
199199
#[inline]
200200
#[stable]
201201
pub fn load(&self, order: Ordering) -> bool {
202-
unsafe { atomic_load(self.v.get() as *const usize, order) > 0 }
202+
unsafe { atomic_load(self.v.get(), order) > 0 }
203203
}
204204

205205
/// Stores a value into the bool.
@@ -438,7 +438,7 @@ impl AtomicIsize {
438438
/// ```
439439
#[inline]
440440
pub fn load(&self, order: Ordering) -> isize {
441-
unsafe { atomic_load(self.v.get() as *const isize, order) }
441+
unsafe { atomic_load(self.v.get(), order) }
442442
}
443443

444444
/// Stores a value into the isize.
@@ -615,7 +615,7 @@ impl AtomicUsize {
615615
/// ```
616616
#[inline]
617617
pub fn load(&self, order: Ordering) -> usize {
618-
unsafe { atomic_load(self.v.get() as *const usize, order) }
618+
unsafe { atomic_load(self.v.get(), order) }
619619
}
620620

621621
/// Stores a value into the usize.
@@ -796,7 +796,7 @@ impl<T> AtomicPtr<T> {
796796
#[stable]
797797
pub fn load(&self, order: Ordering) -> *mut T {
798798
unsafe {
799-
atomic_load(self.p.get() as *const *mut T, order) as *mut T
799+
atomic_load(self.p.get(), order) as *mut T
800800
}
801801
}
802802

@@ -1070,7 +1070,7 @@ impl AtomicInt {
10701070

10711071
#[inline]
10721072
pub fn load(&self, order: Ordering) -> int {
1073-
unsafe { atomic_load(self.v.get() as *const int, order) }
1073+
unsafe { atomic_load(self.v.get(), order) }
10741074
}
10751075

10761076
#[inline]
@@ -1123,7 +1123,7 @@ impl AtomicUint {
11231123

11241124
#[inline]
11251125
pub fn load(&self, order: Ordering) -> uint {
1126-
unsafe { atomic_load(self.v.get() as *const uint, order) }
1126+
unsafe { atomic_load(self.v.get(), order) }
11271127
}
11281128

11291129
#[inline]

src/libcore/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<T> PtrExt for *mut T {
329329
#[inline]
330330
#[stable]
331331
unsafe fn offset(self, count: int) -> *mut T {
332-
intrinsics::offset(self as *const T, count) as *mut T
332+
intrinsics::offset(self, count) as *mut T
333333
}
334334

335335
#[inline]

src/libcore/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ macro_rules! make_slice {
741741
diff / mem::size_of::<$t>()
742742
};
743743
unsafe {
744-
transmute::<_, $result>(RawSlice { data: $start as *const T, len: len })
744+
transmute::<_, $result>(RawSlice { data: $start, len: len })
745745
}
746746
}}
747747
}
@@ -1409,7 +1409,7 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
14091409
#[inline]
14101410
#[unstable = "should be renamed to from_raw_parts_mut"]
14111411
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
1412-
transmute(RawSlice { data: *p as *const T, len: len })
1412+
transmute(RawSlice { data: *p, len: len })
14131413
}
14141414

14151415
//

src/librustc_trans/trans/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Builder<'a, 'tcx: 'a> {
3333
// lot more efficient) than doing str::as_c_str("", ...) every time.
3434
pub fn noname() -> *const c_char {
3535
static CNULL: c_char = 0;
36-
&CNULL as *const c_char
36+
&CNULL
3737
}
3838

3939
impl<'a, 'tcx> Builder<'a, 'tcx> {

src/librustdoc/flock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mod imp {
126126
l_sysid: 0,
127127
};
128128
let ret = unsafe {
129-
libc::fcntl(fd, os::F_SETLKW, &flock as *const os::flock)
129+
libc::fcntl(fd, os::F_SETLKW, &flock)
130130
};
131131
if ret == -1 {
132132
unsafe { libc::close(fd); }
@@ -147,7 +147,7 @@ mod imp {
147147
l_sysid: 0,
148148
};
149149
unsafe {
150-
libc::fcntl(self.fd, os::F_SETLK, &flock as *const os::flock);
150+
libc::fcntl(self.fd, os::F_SETLK, &flock);
151151
libc::close(self.fd);
152152
}
153153
}

src/libstd/collections/hash/table.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,6 @@ impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> FullBucket<K, V, M> {
395395
/// This works similarly to `put`, building an `EmptyBucket` out of the
396396
/// taken bucket.
397397
pub fn take(mut self) -> (EmptyBucket<K, V, M>, K, V) {
398-
let key = self.raw.key as *const K;
399-
let val = self.raw.val as *const V;
400-
401398
self.table.size -= 1;
402399

403400
unsafe {
@@ -408,8 +405,8 @@ impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> FullBucket<K, V, M> {
408405
idx: self.idx,
409406
table: self.table
410407
},
411-
ptr::read(key),
412-
ptr::read(val)
408+
ptr::read(self.raw.key),
409+
ptr::read(self.raw.val)
413410
)
414411
}
415412
}
@@ -477,8 +474,8 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> GapThenFull<K, V, M> {
477474
pub fn shift(mut self) -> Option<GapThenFull<K, V, M>> {
478475
unsafe {
479476
*self.gap.raw.hash = mem::replace(&mut *self.full.raw.hash, EMPTY_BUCKET);
480-
copy_nonoverlapping_memory(self.gap.raw.key, self.full.raw.key as *const K, 1);
481-
copy_nonoverlapping_memory(self.gap.raw.val, self.full.raw.val as *const V, 1);
477+
copy_nonoverlapping_memory(self.gap.raw.key, self.full.raw.key, 1);
478+
copy_nonoverlapping_memory(self.gap.raw.val, self.full.raw.val, 1);
482479
}
483480

484481
let FullBucket { raw: prev_raw, idx: prev_idx, .. } = self.full;
@@ -781,8 +778,8 @@ impl<'a, K, V> Iterator for RevMoveBuckets<'a, K, V> {
781778
if *self.raw.hash != EMPTY_BUCKET {
782779
self.elems_left -= 1;
783780
return Some((
784-
ptr::read(self.raw.key as *const K),
785-
ptr::read(self.raw.val as *const V)
781+
ptr::read(self.raw.key),
782+
ptr::read(self.raw.val)
786783
));
787784
}
788785
}
@@ -878,8 +875,8 @@ impl<K, V> Iterator for IntoIter<K, V> {
878875
SafeHash {
879876
hash: *bucket.hash,
880877
},
881-
ptr::read(bucket.key as *const K),
882-
ptr::read(bucket.val as *const V)
878+
ptr::read(bucket.key),
879+
ptr::read(bucket.val)
883880
)
884881
}
885882
})
@@ -906,8 +903,8 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
906903
SafeHash {
907904
hash: ptr::replace(bucket.hash, EMPTY_BUCKET),
908905
},
909-
ptr::read(bucket.key as *const K),
910-
ptr::read(bucket.val as *const V)
906+
ptr::read(bucket.key),
907+
ptr::read(bucket.val)
911908
)
912909
}
913910
})

src/libstd/sys/unix/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
229229
}
230230

231231
let mut info: Dl_info = unsafe { intrinsics::init() };
232-
if unsafe { dladdr(addr as *const libc::c_void, &mut info) == 0 } {
232+
if unsafe { dladdr(addr, &mut info) == 0 } {
233233
output(w, idx,addr, None)
234234
} else {
235235
output(w, idx, addr, Some(unsafe {

src/libstd/thread_local/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ mod imp {
449449
// destructor as running for this thread so calls to `get` will return
450450
// `None`.
451451
*(*ptr).dtor_running.get() = true;
452-
ptr::read((*ptr).inner.get() as *const T);
452+
ptr::read((*ptr).inner.get());
453453
}
454454
}
455455

0 commit comments

Comments
 (0)