From 68bcc982bf86673985879b8fa8740047f69ced76 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 13 Jan 2022 05:05:35 +0900 Subject: [PATCH] Favor `.cast()` over `as` https://github.com/rust-lang/rust-clippy/issues/8017 --- futures-task/src/future_obj.rs | 2 +- futures-task/src/waker.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/futures-task/src/future_obj.rs b/futures-task/src/future_obj.rs index 48ec12beb2..d0cd9b64c8 100644 --- a/futures-task/src/future_obj.rs +++ b/futures-task/src/future_obj.rs @@ -224,7 +224,7 @@ mod if_alloc { } unsafe fn drop(ptr: *mut (dyn Future + 'a)) { - drop(Box::from_raw(ptr as *mut F)) + drop(Box::from_raw(ptr.cast::())) } } diff --git a/futures-task/src/waker.rs b/futures-task/src/waker.rs index a7310a07af..79112569c5 100644 --- a/futures-task/src/waker.rs +++ b/futures-task/src/waker.rs @@ -20,7 +20,7 @@ pub fn waker(wake: Arc) -> Waker where W: ArcWake + 'static, { - let ptr = Arc::into_raw(wake) as *const (); + let ptr = Arc::into_raw(wake).cast::<()>(); unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::())) } } @@ -31,7 +31,7 @@ where #[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. unsafe fn increase_refcount(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::::from_raw(data as *const T)); + let arc = mem::ManuallyDrop::new(Arc::::from_raw(data.cast::())); // Now increase refcount, but don't drop new refcount either let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); } @@ -43,17 +43,17 @@ unsafe fn clone_arc_raw(data: *const ()) -> RawWaker { } unsafe fn wake_arc_raw(data: *const ()) { - let arc: Arc = Arc::from_raw(data as *const T); + let arc: Arc = Arc::from_raw(data.cast::()); ArcWake::wake(arc); } // used by `waker_ref` unsafe fn wake_by_ref_arc_raw(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::::from_raw(data as *const T)); + let arc = mem::ManuallyDrop::new(Arc::::from_raw(data.cast::())); ArcWake::wake_by_ref(&arc); } unsafe fn drop_arc_raw(data: *const ()) { - drop(Arc::::from_raw(data as *const T)) + drop(Arc::::from_raw(data.cast::())) }