From 8560d01a96f38790299c20b9c34dcc6853a08a00 Mon Sep 17 00:00:00 2001 From: klensy Date: Mon, 25 Mar 2024 23:19:40 +0300 Subject: [PATCH] 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::()); | ^^^^^^^^^^^^ 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::()); | ^^^^^^^^^^^^ help: try: `len` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast --- library/alloc/src/collections/btree/map/entry.rs | 2 +- library/alloc/src/ffi/c_str.rs | 2 +- library/alloc/src/slice.rs | 8 ++++---- library/alloc/src/task.rs | 4 ++-- library/std/src/sys_common/net.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index 0a894258f469f..66eb991c6d4b8 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -354,7 +354,7 @@ impl<'a, K: Ord, V, A: Allocator + Clone> VacantEntry<'a, K, V, A> { // SAFETY: There is no tree yet so no reference to it exists. let map = unsafe { self.dormant_map.awaken() }; let mut root = NodeRef::new_leaf(self.alloc.clone()); - let val_ptr = root.borrow_mut().push(self.key, value) as *mut V; + let val_ptr = root.borrow_mut().push(self.key, value); map.root = Some(root.forget_type()); map.length = 1; val_ptr diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 0c7f94ccceb02..6a64eaf576bb9 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -408,7 +408,7 @@ impl CString { fn strlen(s: *const c_char) -> usize; } let len = strlen(ptr) + 1; // Including the NUL byte - let slice = slice::from_raw_parts_mut(ptr, len as usize); + let slice = slice::from_raw_parts_mut(ptr, len); CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) } } } diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 21d5dce04a0fc..ebe6f7e7caa9b 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -511,9 +511,9 @@ impl [T] { while m > 0 { // `buf.extend(buf)`: unsafe { - ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping::( buf.as_ptr(), - (buf.as_mut_ptr() as *mut T).add(buf.len()), + (buf.as_mut_ptr()).add(buf.len()), buf.len(), ); // `buf` has capacity of `self.len() * n`. @@ -532,9 +532,9 @@ impl [T] { // `buf.extend(buf[0 .. rem_len])`: unsafe { // This is non-overlapping since `2^expn > rem`. - ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping::( buf.as_ptr(), - (buf.as_mut_ptr() as *mut T).add(buf.len()), + (buf.as_mut_ptr()).add(buf.len()), rem_len, ); // `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`). diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index b40768a52b6b4..a3fa6585a37f8 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -148,7 +148,7 @@ fn raw_waker(waker: Arc) -> RawWaker { unsafe fn clone_waker(waker: *const ()) -> RawWaker { unsafe { Arc::increment_strong_count(waker as *const W) }; RawWaker::new( - waker as *const (), + waker, &RawWakerVTable::new(clone_waker::, wake::, wake_by_ref::, drop_waker::), ) } @@ -320,7 +320,7 @@ fn local_raw_waker(waker: Rc) -> RawWaker { unsafe fn clone_waker(waker: *const ()) -> RawWaker { unsafe { Rc::increment_strong_count(waker as *const W) }; RawWaker::new( - waker as *const (), + waker, &RawWakerVTable::new(clone_waker::, wake::, wake_by_ref::, drop_waker::), ) } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 581c46af0eacf..2d785064245dc 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -107,13 +107,13 @@ where pub fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result { match storage.ss_family as c_int { c::AF_INET => { - assert!(len as usize >= mem::size_of::()); + assert!(len >= mem::size_of::()); Ok(SocketAddr::V4(FromInner::from_inner(unsafe { *(storage as *const _ as *const c::sockaddr_in) }))) } c::AF_INET6 => { - assert!(len as usize >= mem::size_of::()); + assert!(len >= mem::size_of::()); Ok(SocketAddr::V6(FromInner::from_inner(unsafe { *(storage as *const _ as *const c::sockaddr_in6) })))