Skip to content

Commit 66d7688

Browse files
committed
Fix stacked borrows violations in waker_ref and FuturesUnordered (#2550)
1 parent fe86d0a commit 66d7688

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ jobs:
5656
if: matrix.target != 'aarch64-unknown-linux-gnu'
5757

5858
core-msrv:
59-
name: cargo +${{ matrix.rust }} build (futures-{core, io, sink, task})
59+
name: cargo +${{ matrix.rust }} build (futures-{core, io, sink})
6060
strategy:
6161
matrix:
6262
rust:
63-
# This is the minimum Rust version supported by futures-core, futures-io, futures-sink, futures-task.
63+
# This is the minimum Rust version supported by futures-core, futures-io, futures-sink.
6464
# When updating this, the reminder to update the minimum required version in README.md, Cargo.toml, and .clippy.toml.
6565
- 1.36
6666
runs-on: ubuntu-latest
@@ -76,22 +76,22 @@ jobs:
7676
# Check no-default-features
7777
- run: |
7878
cargo hack build --workspace --ignore-private --no-default-features \
79-
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
79+
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
8080
# Check alloc feature
8181
- run: |
8282
cargo hack build --workspace --ignore-private --no-default-features --features alloc --ignore-unknown-features \
83-
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
83+
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
8484
# Check std feature
8585
- run: |
8686
cargo hack build --workspace --ignore-private --no-default-features --features std \
87-
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
87+
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
8888
8989
util-msrv:
9090
name: cargo +${{ matrix.rust }} build
9191
strategy:
9292
matrix:
9393
rust:
94-
# This is the minimum Rust version supported by futures, futures-util, futures-macro, futures-executor, futures-channel, futures-test.
94+
# This is the minimum Rust version supported by futures, futures-util, futures-task, futures-macro, futures-executor, futures-channel, futures-test.
9595
# When updating this, the reminder to update the minimum required version in README.md and Cargo.toml.
9696
- 1.45
9797
runs-on: ubuntu-latest

futures-task/src/waker_ref.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)