From 14aeaa3c06fc527a10047d42733486b578f16496 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Sat, 11 Jan 2025 13:35:09 +1100 Subject: [PATCH] Improve Compiler Errors for `bevy_tasks` (#17296) # Objective - Fixes #17287 ## Solution - Added a dummy `LocalExecutor` (un)implementation to suppress irrelevant errors. - Added explicit `compiler_error!` when _not_ selecting either the `async_executor` or `edge_executor` features ## Testing - CI --- crates/bevy_tasks/src/lib.rs | 4 ++ .../src/single_threaded_task_pool.rs | 42 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/bevy_tasks/src/lib.rs b/crates/bevy_tasks/src/lib.rs index 16ff97bd74..7b1438d4b2 100644 --- a/crates/bevy_tasks/src/lib.rs +++ b/crates/bevy_tasks/src/lib.rs @@ -16,6 +16,9 @@ extern crate std; extern crate alloc; +#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))] +compile_error!("Either of the `async_executor` or the `edge_executor` features must be enabled."); + #[cfg(not(target_arch = "wasm32"))] mod conditional_send { /// Use [`ConditionalSend`] to mark an optional Send trait bound. Useful as on certain platforms (eg. Wasm), @@ -45,6 +48,7 @@ pub type BoxedFuture<'a, T> = core::pin::Pin(PhantomData); + + impl<'a> LocalExecutor<'a> { + /// Dummy implementation + pub const fn new() -> Self { + Self(PhantomData) + } + + /// Dummy implementation + pub fn try_tick(&self) -> bool { + unimplemented!() + } + + /// Dummy implementation + pub fn spawn(&self, _: impl Future + 'a) -> Task { + unimplemented!() + } + } +} + +#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))] +use dummy_executor::LocalExecutor; + #[cfg(feature = "std")] thread_local! { static LOCAL_EXECUTOR: LocalExecutor<'static> = const { LocalExecutor::new() };