Skip to content

Commit 8f40f46

Browse files
committed
Use Arc::as_ptr
This fixes stacked borrows violations with -Zmiri-tag-raw-pointers.
1 parent 72f4f80 commit 8f40f46

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
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/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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<Fut> ReadyToRunQueue<Fut> {
8383
}
8484

8585
pub(super) fn stub(&self) -> *const Task<Fut> {
86-
&*self.stub
86+
Arc::as_ptr(&self.stub)
8787
}
8888

8989
// Clear the queue of tasks.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<Fut> ArcWake for Task<Fut> {
6262
// still.
6363
let prev = arc_self.queued.swap(true, SeqCst);
6464
if !prev {
65-
inner.enqueue(&**arc_self);
65+
inner.enqueue(Arc::as_ptr(arc_self));
6666
inner.waker.wake();
6767
}
6868
}

0 commit comments

Comments
 (0)