Replace noop waker implementation with Waker::noop().

The MSRV of `wgpu` is currently 1.88, so we can use `Waker::noop()`,
which was stabilized in 1.85.
This commit is contained in:
Kevin Reid 2025-11-01 09:13:22 -07:00 committed by Andy Leiserson
parent abff8ae375
commit 2a58599dc4

View File

@ -58,7 +58,7 @@ impl Device {
use core::future::Future as _;
use core::pin::pin;
use core::task;
let ctx = &mut task::Context::from_waker(waker::noop_waker_ref());
let ctx = &mut task::Context::from_waker(task::Waker::noop());
let instance = Instance::new(&InstanceDescriptor {
backends: Backends::NOOP,
@ -795,36 +795,3 @@ impl fmt::Display for Error {
}
}
}
// Copied from [`futures::task::noop_waker`].
// Needed until MSRV is 1.85 with `task::Waker::noop()` available
#[cfg(feature = "noop")]
mod waker {
use core::ptr::null;
use core::task::{RawWaker, RawWakerVTable, Waker};
unsafe fn noop_clone(_data: *const ()) -> RawWaker {
noop_raw_waker()
}
unsafe fn noop(_data: *const ()) {}
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
const fn noop_raw_waker() -> RawWaker {
RawWaker::new(null(), &NOOP_WAKER_VTABLE)
}
/// Get a static reference to a [`Waker`] which
/// does nothing when `wake()` is called on it.
#[inline]
pub fn noop_waker_ref() -> &'static Waker {
struct SyncRawWaker(RawWaker);
unsafe impl Sync for SyncRawWaker {}
static NOOP_WAKER_INSTANCE: SyncRawWaker = SyncRawWaker(noop_raw_waker());
// SAFETY: `Waker` is #[repr(transparent)] over its `RawWaker`.
unsafe { &*(&NOOP_WAKER_INSTANCE.0 as *const RawWaker as *const Waker) }
}
}