Skip to content

Commit 0e72d61

Browse files
committed
wip
1 parent d3d8119 commit 0e72d61

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ jobs:
244244
- name: Install Rust
245245
run: rustup toolchain install nightly --component miri && rustup default nightly
246246
# futures-executor uses boxed futures so many tests trigger https://github.com/rust-lang/miri/issues/1038
247-
- run: cargo miri test --workspace --exclude futures-executor --all-features
247+
- run: cargo miri test --workspace --exclude futures-executor --all-features --no-fail-fast
248248
env:
249-
MIRIFLAGS: -Zmiri-disable-isolation # TODO: use -Zmiri-tag-raw-pointers
249+
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-tag-raw-pointers
250250

251251
san:
252252
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}

futures-task/src/future_obj.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mod if_alloc {
224224
}
225225

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

@@ -252,10 +252,9 @@ mod if_alloc {
252252
where
253253
F: Future<Output = T> + 'a,
254254
{
255-
fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) {
256-
let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ };
257-
mem::forget(self);
258-
ptr
255+
fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) {
256+
let mut this = mem::ManuallyDrop::new(self);
257+
unsafe { this.as_mut().get_unchecked_mut() as *mut _ }
259258
}
260259

261260
unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) {
@@ -264,10 +263,9 @@ mod if_alloc {
264263
}
265264

266265
unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + 'a>> {
267-
fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) {
268-
let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ };
269-
mem::forget(self);
270-
ptr
266+
fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) {
267+
let mut this = mem::ManuallyDrop::new(self);
268+
unsafe { this.as_mut().get_unchecked_mut() as *mut _ }
271269
}
272270

273271
unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) {
@@ -276,10 +274,9 @@ mod if_alloc {
276274
}
277275

278276
unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + Send + 'a>> {
279-
fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) {
280-
let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ };
281-
mem::forget(self);
282-
ptr
277+
fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) {
278+
let mut this = mem::ManuallyDrop::new(self);
279+
unsafe { this.as_mut().get_unchecked_mut() as *mut _ }
283280
}
284281

285282
unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) {

futures-task/src/waker.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn waker<W>(wake: Arc<W>) -> Waker
2020
where
2121
W: ArcWake + 'static,
2222
{
23-
let ptr = Arc::into_raw(wake) as *const ();
23+
let ptr = Arc::into_raw(wake).cast::<()>();
2424

2525
unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) }
2626
}
@@ -31,7 +31,7 @@ where
3131
#[allow(clippy::redundant_clone)] // The clone here isn't actually redundant.
3232
unsafe fn increase_refcount<T: ArcWake>(data: *const ()) {
3333
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
34-
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));
34+
let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>()));
3535
// Now increase refcount, but don't drop new refcount either
3636
let _arc_clone: mem::ManuallyDrop<_> = arc.clone();
3737
}
@@ -43,17 +43,17 @@ unsafe fn clone_arc_raw<T: ArcWake>(data: *const ()) -> RawWaker {
4343
}
4444

4545
unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) {
46-
let arc: Arc<T> = Arc::from_raw(data as *const T);
46+
let arc: Arc<T> = Arc::from_raw(data.cast::<T>());
4747
ArcWake::wake(arc);
4848
}
4949

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

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

futures-task/src/waker_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
{
5656
// simply copy the pointer instead of using Arc::into_raw,
5757
// as we don't actually keep a refcount by using ManuallyDrop.<
58-
let ptr = (&**wake as *const W) as *const ();
58+
let ptr = Arc::as_ptr(wake).cast::<()>();
5959

6060
let waker =
6161
ManuallyDrop::new(unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) });

futures-util/src/stream/futures_unordered/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<Fut> FuturesUnordered<Fut> {
150150
queued: AtomicBool::new(true),
151151
ready_to_run_queue: Weak::new(),
152152
});
153-
let stub_ptr = &*stub as *const Task<Fut>;
153+
let stub_ptr = Arc::as_ptr(&stub);
154154
let ready_to_run_queue = Arc::new(ReadyToRunQueue {
155155
waker: AtomicWaker::new(),
156156
head: AtomicPtr::new(stub_ptr as *mut _),
@@ -403,7 +403,7 @@ impl<Fut> FuturesUnordered<Fut> {
403403
// The `ReadyToRunQueue` stub is never inserted into the `head_all`
404404
// list, and its pointer value will remain valid for the lifetime of
405405
// this `FuturesUnordered`, so we can make use of its value here.
406-
&*self.ready_to_run_queue.stub as *const _ as *mut _
406+
Arc::as_ptr(&self.ready_to_run_queue.stub) as *mut _
407407
}
408408
}
409409

0 commit comments

Comments
 (0)