Skip to content

Commit

Permalink
Fix stacked borrows violations in waker_ref and FuturesUnordered (#2550)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 6, 2022
1 parent 0e6f9d9 commit b297565
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -56,11 +56,11 @@ jobs:
if: matrix.target != 'aarch64-unknown-linux-gnu'

core-msrv:
name: cargo +${{ matrix.rust }} build (futures-{core, io, sink, task})
name: cargo +${{ matrix.rust }} build (futures-{core, io, sink})
strategy:
matrix:
rust:
# This is the minimum Rust version supported by futures-core, futures-io, futures-sink, futures-task.
# This is the minimum Rust version supported by futures-core, futures-io, futures-sink.
# When updating this, the reminder to update the minimum required version in README.md, Cargo.toml, and .clippy.toml.
- 1.36
runs-on: ubuntu-latest
Expand All @@ -76,22 +76,22 @@ jobs:
# Check no-default-features
- run: |
cargo hack build --workspace --ignore-private --no-default-features \
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
# Check alloc feature
- run: |
cargo hack build --workspace --ignore-private --no-default-features --features alloc --ignore-unknown-features \
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
# Check std feature
- run: |
cargo hack build --workspace --ignore-private --no-default-features --features std \
--exclude futures --exclude futures-util --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
--exclude futures --exclude futures-util --exclude futures-task --exclude futures-macro --exclude futures-executor --exclude futures-channel --exclude futures-test
util-msrv:
name: cargo +${{ matrix.rust }} build
strategy:
matrix:
rust:
# This is the minimum Rust version supported by futures, futures-util, futures-macro, futures-executor, futures-channel, futures-test.
# This is the minimum Rust version supported by futures, futures-util, futures-task, futures-macro, futures-executor, futures-channel, futures-test.
# When updating this, the reminder to update the minimum required version in README.md and Cargo.toml.
- 1.45
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion futures-task/src/waker_ref.rs
Expand Up @@ -55,7 +55,7 @@ where
{
// simply copy the pointer instead of using Arc::into_raw,
// as we don't actually keep a refcount by using ManuallyDrop.<
let ptr = (&**wake as *const W) as *const ();
let ptr = Arc::as_ptr(wake).cast::<()>();

let waker =
ManuallyDrop::new(unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) });
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/stream/futures_unordered/mod.rs
Expand Up @@ -150,7 +150,7 @@ impl<Fut> FuturesUnordered<Fut> {
queued: AtomicBool::new(true),
ready_to_run_queue: Weak::new(),
});
let stub_ptr = &*stub as *const Task<Fut>;
let stub_ptr = Arc::as_ptr(&stub);
let ready_to_run_queue = Arc::new(ReadyToRunQueue {
waker: AtomicWaker::new(),
head: AtomicPtr::new(stub_ptr as *mut _),
Expand Down Expand Up @@ -403,7 +403,7 @@ impl<Fut> FuturesUnordered<Fut> {
// The `ReadyToRunQueue` stub is never inserted into the `head_all`
// list, and its pointer value will remain valid for the lifetime of
// this `FuturesUnordered`, so we can make use of its value here.
&*self.ready_to_run_queue.stub as *const _ as *mut _
Arc::as_ptr(&self.ready_to_run_queue.stub) as *mut _
}
}

Expand Down
Expand Up @@ -83,7 +83,7 @@ impl<Fut> ReadyToRunQueue<Fut> {
}

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

// Clear the queue of tasks.
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/futures_unordered/task.rs
Expand Up @@ -62,7 +62,7 @@ impl<Fut> ArcWake for Task<Fut> {
// still.
let prev = arc_self.queued.swap(true, SeqCst);
if !prev {
inner.enqueue(&**arc_self);
inner.enqueue(Arc::as_ptr(arc_self));
inner.waker.wake();
}
}
Expand Down

0 comments on commit b297565

Please sign in to comment.