Skip to content

Commit 241d8a4

Browse files
committed
Rollup merge of rust-lang#21375 - petrochenkov:ssbsl, r=alexcrichton
After PR rust-lang#19766 added implicit coersions `*mut T -> *const T`, the explicit casts can be removed. (The number of such casts turned out to be relatively small).
2 parents 8b5f3ce + 812ce6c commit 241d8a4

File tree

14 files changed

+39
-42
lines changed

14 files changed

+39
-42
lines changed

src/doc/trpl/unsafe.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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);
@@ -879,7 +879,7 @@ impl<T> Vec<T> {
879879
// | |
880880
// end_u end_t
881881

882-
let t = ptr::read(pv.start_t as *const T);
882+
let t = ptr::read(pv.start_t);
883883
// start_u start_t
884884
// | |
885885
// +-+-+-+-+-+-+-+-+-+
@@ -1443,7 +1443,7 @@ impl<T> AsSlice<T> for Vec<T> {
14431443
fn as_slice<'a>(&'a self) -> &'a [T] {
14441444
unsafe {
14451445
mem::transmute(RawSlice {
1446-
data: *self.ptr as *const T,
1446+
data: *self.ptr,
14471447
len: self.len
14481448
})
14491449
}
@@ -1806,11 +1806,11 @@ impl<T,U> Drop for PartialVecNonZeroSized<T,U> {
18061806

18071807
// We have instances of `U`s and `T`s in `vec`. Destruct them.
18081808
while self.start_u != self.end_u {
1809-
let _ = ptr::read(self.start_u as *const U); // Run a `U` destructor.
1809+
let _ = ptr::read(self.start_u); // Run a `U` destructor.
18101810
self.start_u = self.start_u.offset(1);
18111811
}
18121812
while self.start_t != self.end_t {
1813-
let _ = ptr::read(self.start_t as *const T); // Run a `T` destructor.
1813+
let _ = ptr::read(self.start_t); // Run a `T` destructor.
18141814
self.start_t = self.start_t.offset(1);
18151815
}
18161816
// After this destructor ran, the destructor of `vec` will run,

src/libcore/atomic.rs

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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> {

0 commit comments

Comments
 (0)