Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stacked borrows violations with -Zmiri-tag-raw-pointers in waker_ref and FuturesUnordered #2550

Merged
merged 1 commit into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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