From 539ff78ebbdedbb75d0faf940e3ee69f5e7f276a Mon Sep 17 00:00:00 2001 From: Brezak Date: Wed, 23 Jul 2025 19:51:31 +0200 Subject: embassy-executor: explicitly return impl Future in task inner task --- embassy-executor/src/lib.rs | 8 ++++---- embassy-executor/tests/test.rs | 11 ++++++++++- .../tests/ui/bad_return_impl_future_nightly.stderr | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index e174a0594..0747db032 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -216,7 +216,7 @@ pub mod _export { ); #[allow(dead_code)] - trait HasOutput { + pub trait HasOutput { type Output; } @@ -225,7 +225,7 @@ pub mod _export { } #[allow(dead_code)] - type Never = ! as HasOutput>::Output; + pub type Never = ! as HasOutput>::Output; } /// Implementation details for embassy macros. @@ -242,7 +242,7 @@ pub mod _export { impl TaskReturnValue for Never {} #[allow(dead_code)] - trait HasOutput { + pub trait HasOutput { type Output; } @@ -251,5 +251,5 @@ pub mod _export { } #[allow(dead_code)] - type Never = ! as HasOutput>::Output; + pub type Never = ! as HasOutput>::Output; } diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index c1e7ec5d7..b84d3785a 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex}; use std::task::Poll; use embassy_executor::raw::Executor; -use embassy_executor::task; +use embassy_executor::{task, Spawner}; #[export_name = "__pender"] fn __pender(context: *mut ()) { @@ -317,3 +317,12 @@ fn executor_task_cfg_args() { let (_, _, _) = (a, b, c); } } + +#[test] +fn recursive_task() { + #[embassy_executor::task(pool_size = 2)] + async fn task1() { + let spawner = unsafe { Spawner::for_current_executor().await }; + spawner.spawn(task1()); + } +} diff --git a/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr index 73ceb989d..3c3c9503b 100644 --- a/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr +++ b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr @@ -7,4 +7,4 @@ error[E0277]: task futures must resolve to `()` or `!` = note: use `async fn` or change the return type to `impl Future` = help: the following other types implement trait `TaskReturnValue`: () - ! as _export::HasOutput>::Output + ! as HasOutput>::Output -- cgit