Skip to content

Commit 8560d01

Browse files
committed
lib: fix some unnecessary_cast clippy lint
warning: casting raw pointers to the same type and constness is unnecessary (`*mut V` -> `*mut V`) --> library\alloc\src\collections\btree\map\entry.rs:357:31 | 357 | let val_ptr = root.borrow_mut().push(self.key, value) as *mut V; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `root.borrow_mut().push (self.key, value)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting to the same type is unnecessary (`usize` -> `usize`) --> library\alloc\src\ffi\c_str.rs:411:56 | 411 | let slice = slice::from_raw_parts_mut(ptr, len as usize); | ^^^^^^^^^^^^ help: try: `len` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting raw pointers to the same type and constness is unnecessary (`*mut T` -> `*mut T`) --> library\alloc\src\slice.rs:516:25 | 516 | (buf.as_mut_ptr() as *mut T).add(buf.len()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `buf.as_mut_ptr()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting raw pointers to the same type and constness is unnecessary (`*mut T` -> `*mut T`) --> library\alloc\src\slice.rs:537:21 | 537 | (buf.as_mut_ptr() as *mut T).add(buf.len()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `buf.as_mut_ptr()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting raw pointers to the same type and constness is unnecessary (`*const ()` -> `*const ()`) --> library\alloc\src\task.rs:151:13 | 151 | waker as *const (), | ^^^^^^^^^^^^^^^^^^ help: try: `waker` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting raw pointers to the same type and constness is unnecessary (`*const ()` -> `*const ()`) --> library\alloc\src\task.rs:323:13 | 323 | waker as *const (), | ^^^^^^^^^^^^^^^^^^ help: try: `waker` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting to the same type is unnecessary (`usize` -> `usize`) --> library\std\src\sys_common\net.rs:110:21 | 110 | assert!(len as usize >= mem::size_of::<c::sockaddr_in>()); | ^^^^^^^^^^^^ help: try: `len` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast warning: casting to the same type is unnecessary (`usize` -> `usize`) --> library\std\src\sys_common\net.rs:116:21 | 116 | assert!(len as usize >= mem::size_of::<c::sockaddr_in6>()); | ^^^^^^^^^^^^ help: try: `len` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
1 parent 42198bf commit 8560d01

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

library/alloc/src/collections/btree/map/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'a, K: Ord, V, A: Allocator + Clone> VacantEntry<'a, K, V, A> {
354354
// SAFETY: There is no tree yet so no reference to it exists.
355355
let map = unsafe { self.dormant_map.awaken() };
356356
let mut root = NodeRef::new_leaf(self.alloc.clone());
357-
let val_ptr = root.borrow_mut().push(self.key, value) as *mut V;
357+
let val_ptr = root.borrow_mut().push(self.key, value);
358358
map.root = Some(root.forget_type());
359359
map.length = 1;
360360
val_ptr

library/alloc/src/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl CString {
408408
fn strlen(s: *const c_char) -> usize;
409409
}
410410
let len = strlen(ptr) + 1; // Including the NUL byte
411-
let slice = slice::from_raw_parts_mut(ptr, len as usize);
411+
let slice = slice::from_raw_parts_mut(ptr, len);
412412
CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) }
413413
}
414414
}

library/alloc/src/slice.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ impl<T> [T] {
511511
while m > 0 {
512512
// `buf.extend(buf)`:
513513
unsafe {
514-
ptr::copy_nonoverlapping(
514+
ptr::copy_nonoverlapping::<T>(
515515
buf.as_ptr(),
516-
(buf.as_mut_ptr() as *mut T).add(buf.len()),
516+
(buf.as_mut_ptr()).add(buf.len()),
517517
buf.len(),
518518
);
519519
// `buf` has capacity of `self.len() * n`.
@@ -532,9 +532,9 @@ impl<T> [T] {
532532
// `buf.extend(buf[0 .. rem_len])`:
533533
unsafe {
534534
// This is non-overlapping since `2^expn > rem`.
535-
ptr::copy_nonoverlapping(
535+
ptr::copy_nonoverlapping::<T>(
536536
buf.as_ptr(),
537-
(buf.as_mut_ptr() as *mut T).add(buf.len()),
537+
(buf.as_mut_ptr()).add(buf.len()),
538538
rem_len,
539539
);
540540
// `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).

library/alloc/src/task.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
148148
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
149149
unsafe { Arc::increment_strong_count(waker as *const W) };
150150
RawWaker::new(
151-
waker as *const (),
151+
waker,
152152
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
153153
)
154154
}
@@ -320,7 +320,7 @@ fn local_raw_waker<W: LocalWake + 'static>(waker: Rc<W>) -> RawWaker {
320320
unsafe fn clone_waker<W: LocalWake + 'static>(waker: *const ()) -> RawWaker {
321321
unsafe { Rc::increment_strong_count(waker as *const W) };
322322
RawWaker::new(
323-
waker as *const (),
323+
waker,
324324
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
325325
)
326326
}

library/std/src/sys_common/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ where
107107
pub fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result<SocketAddr> {
108108
match storage.ss_family as c_int {
109109
c::AF_INET => {
110-
assert!(len as usize >= mem::size_of::<c::sockaddr_in>());
110+
assert!(len >= mem::size_of::<c::sockaddr_in>());
111111
Ok(SocketAddr::V4(FromInner::from_inner(unsafe {
112112
*(storage as *const _ as *const c::sockaddr_in)
113113
})))
114114
}
115115
c::AF_INET6 => {
116-
assert!(len as usize >= mem::size_of::<c::sockaddr_in6>());
116+
assert!(len >= mem::size_of::<c::sockaddr_in6>());
117117
Ok(SocketAddr::V6(FromInner::from_inner(unsafe {
118118
*(storage as *const _ as *const c::sockaddr_in6)
119119
})))

0 commit comments

Comments
 (0)