Skip to content

Commit

Permalink
Favor .cast() over as
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 12, 2022
1 parent 02db501 commit 6e022e4
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion futures-task/src/future_obj.rs
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ mod if_alloc {
}

unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) {
drop(Box::from_raw(ptr as *mut F))
drop(Box::from_raw(ptr.cast::<F>()))
}
}

10 changes: 5 additions & 5 deletions futures-task/src/waker.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ pub fn waker<W>(wake: Arc<W>) -> 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::<W>())) }
}
@@ -31,7 +31,7 @@ where
#[allow(clippy::redundant_clone)] // The clone here isn't actually redundant.
unsafe fn increase_refcount<T: ArcWake>(data: *const ()) {
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>()));
// 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<T: ArcWake>(data: *const ()) -> RawWaker {
}

unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) {
let arc: Arc<T> = Arc::from_raw(data as *const T);
let arc: Arc<T> = Arc::from_raw(data.cast::<T>());
ArcWake::wake(arc);
}

// used by `waker_ref`
unsafe fn wake_by_ref_arc_raw<T: ArcWake>(data: *const ()) {
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>()));
ArcWake::wake_by_ref(&arc);
}

unsafe fn drop_arc_raw<T: ArcWake>(data: *const ()) {
drop(Arc::<T>::from_raw(data as *const T))
drop(Arc::<T>::from_raw(data.cast::<T>()))
}

0 comments on commit 6e022e4

Please sign in to comment.