From a4d4f62a1e0e808ec3dd93e282f517a2f8ad9fa5 Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Wed, 28 May 2025 22:00:25 -0500 Subject: Allow `-> impl Future` in #[task] --- embassy-executor/src/lib.rs | 47 +++++++- embassy-executor/tests/test.rs | 24 ++++- embassy-executor/tests/ui.rs | 4 + embassy-executor/tests/ui/bad_return_impl_trait.rs | 9 ++ .../tests/ui/bad_return_impl_trait.stderr | 120 +++++++++++++++++++++ .../tests/ui/bad_return_impl_trait_nightly.rs | 9 ++ .../tests/ui/bad_return_impl_trait_nightly.stderr | 9 ++ 7 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 embassy-executor/tests/ui/bad_return_impl_trait.rs create mode 100644 embassy-executor/tests/ui/bad_return_impl_trait.stderr create mode 100644 embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs create mode 100644 embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr (limited to 'embassy-executor') diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index dfe420bab..70abfcc3a 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -65,8 +65,17 @@ pub mod _export { use crate::raw::TaskPool; + trait TaskReturnValue {} + impl TaskReturnValue for () {} + impl TaskReturnValue for Never {} + + #[diagnostic::on_unimplemented( + message = "task function futures must resolve to `()`", + note = "use `async fn` or change the return type to `impl Future`" + )] + #[allow(private_bounds)] pub trait TaskFn: Copy { - type Fut: Future + 'static; + type Fut: Future + 'static; } macro_rules! task_fn_impl { @@ -74,7 +83,7 @@ pub mod _export { impl TaskFn<($($Tn,)*)> for F where F: Copy + FnOnce($($Tn,)*) -> Fut, - Fut: Future + 'static, + Fut: Future + 'static, { type Fut = Fut; } @@ -205,4 +214,38 @@ pub mod _export { Align268435456: 268435456, Align536870912: 536870912, ); + + #[allow(dead_code)] + trait HasOutput { + type Output; + } + + impl HasOutput for fn() -> O { + type Output = O; + } + + #[allow(dead_code)] + type Never = ! as HasOutput>::Output; +} + +/// Implementation details for embassy macros. +/// Do not use. Used for macros and HALs only. Not covered by semver guarantees. +#[doc(hidden)] +#[cfg(feature = "nightly")] +pub mod _export { + pub trait TaskReturnValue {} + impl TaskReturnValue for () {} + impl TaskReturnValue for Never {} + + #[allow(dead_code)] + trait HasOutput { + type Output; + } + + impl HasOutput for fn() -> O { + type Output = O; + } + + #[allow(dead_code)] + type Never = ! as HasOutput>::Output; } diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 78c49c071..c7ff4554c 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs @@ -1,7 +1,7 @@ #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] use std::boxed::Box; -use std::future::poll_fn; +use std::future::{poll_fn, Future}; use std::sync::{Arc, Mutex}; use std::task::Poll; @@ -73,6 +73,28 @@ fn executor_task() { ) } +#[test] +fn executor_task_rpit() { + #[task] + fn task1(trace: Trace) -> impl Future { + async move { trace.push("poll task1") } + } + + let (executor, trace) = setup(); + executor.spawner().spawn(task1(trace.clone())).unwrap(); + + unsafe { executor.poll() }; + unsafe { executor.poll() }; + + assert_eq!( + trace.get(), + &[ + "pend", // spawning a task pends the executor + "poll task1", // poll only once. + ] + ) +} + #[test] fn executor_task_self_wake() { #[task] diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs index 278a4b903..ed8228e27 100644 --- a/embassy-executor/tests/ui.rs +++ b/embassy-executor/tests/ui.rs @@ -17,6 +17,10 @@ fn ui() { t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); t.compile_fail("tests/ui/not_async.rs"); + // #[cfg(not(feature = "nightly"))] // output differs on stable and nightly + // t.compile_fail("tests/ui/bad_return_impl_trait.rs"); + #[cfg(feature = "nightly")] + t.compile_fail("tests/ui/bad_return_impl_trait_nightly.rs"); t.compile_fail("tests/ui/self_ref.rs"); t.compile_fail("tests/ui/self.rs"); t.compile_fail("tests/ui/type_error.rs"); diff --git a/embassy-executor/tests/ui/bad_return_impl_trait.rs b/embassy-executor/tests/ui/bad_return_impl_trait.rs new file mode 100644 index 000000000..baaa7dc5a --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_trait.rs @@ -0,0 +1,9 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] +use core::future::Future; + +#[embassy_executor::task] +fn task() -> impl Future { + async { 5 } +} + +fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_trait.stderr b/embassy-executor/tests/ui/bad_return_impl_trait.stderr new file mode 100644 index 000000000..9e2df353e --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_trait.stderr @@ -0,0 +1,120 @@ +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_size` + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_align` + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_new` + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task function futures must resolve to `()` + --> tests/ui/bad_return_impl_trait.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `__task_pool_get` + --> tests/ui/bad_return_impl_trait.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs new file mode 100644 index 000000000..baaa7dc5a --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs @@ -0,0 +1,9 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] +use core::future::Future; + +#[embassy_executor::task] +fn task() -> impl Future { + async { 5 } +} + +fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr new file mode 100644 index 000000000..21e20d5c0 --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `u32: TaskReturnValue` is not satisfied + --> tests/ui/bad_return_impl_trait_nightly.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` + | + = help: the following other types implement trait `TaskReturnValue`: + () + ! as _export::HasOutput>::Output -- cgit From dbff432e19b326d7cef109bc4d2a0cd51260562d Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Thu, 29 May 2025 05:18:16 -0500 Subject: Add test for -> impl Future --- embassy-executor/tests/test.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'embassy-executor') diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index c7ff4554c..c1e7ec5d7 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] +#![cfg_attr(feature = "nightly", feature(never_type))] use std::boxed::Box; use std::future::{poll_fn, Future}; @@ -58,6 +59,11 @@ fn executor_task() { trace.push("poll task1") } + #[task] + async fn task2() -> ! { + panic!() + } + let (executor, trace) = setup(); executor.spawner().spawn(task1(trace.clone())).unwrap(); @@ -80,6 +86,12 @@ fn executor_task_rpit() { async move { trace.push("poll task1") } } + #[cfg(feature = "nightly")] + #[task] + fn task2() -> impl Future { + async { panic!() } + } + let (executor, trace) = setup(); executor.spawner().spawn(task1(trace.clone())).unwrap(); -- cgit From b06a708f81d208236763a121797807fd5b48aee6 Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Thu, 29 May 2025 05:54:25 -0500 Subject: Mention ! in diagnostic --- embassy-executor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 70abfcc3a..e26e8ee7d 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -70,7 +70,7 @@ pub mod _export { impl TaskReturnValue for Never {} #[diagnostic::on_unimplemented( - message = "task function futures must resolve to `()`", + message = "task futures must resolve to `()` or `!`", note = "use `async fn` or change the return type to `impl Future`" )] #[allow(private_bounds)] -- cgit From 0d83fbbb57cf17186a1b8f40f57ef7a35b3e9627 Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Sun, 1 Jun 2025 10:32:24 -0500 Subject: Add diagnostic::on_unimplemented for nightly --- embassy-executor/src/lib.rs | 4 ++++ embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index e26e8ee7d..e174a0594 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -233,6 +233,10 @@ pub mod _export { #[doc(hidden)] #[cfg(feature = "nightly")] pub mod _export { + #[diagnostic::on_unimplemented( + message = "task futures must resolve to `()` or `!`", + note = "use `async fn` or change the return type to `impl Future`" + )] pub trait TaskReturnValue {} impl TaskReturnValue for () {} impl TaskReturnValue for Never {} diff --git a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr index 21e20d5c0..a51251bb8 100644 --- a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr +++ b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr @@ -1,9 +1,10 @@ -error[E0277]: the trait bound `u32: TaskReturnValue` is not satisfied +error[E0277]: task futures must resolve to `()` or `!` --> tests/ui/bad_return_impl_trait_nightly.rs:4:1 | 4 | #[embassy_executor::task] | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` | + = note: use `async fn` or change the return type to `impl Future` = help: the following other types implement trait `TaskReturnValue`: () ! as _export::HasOutput>::Output -- cgit From 3cef4f0c04a1f0f56c84950d8fd408979299fa50 Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Sun, 1 Jun 2025 11:42:33 -0500 Subject: Update tests --- embassy-executor/Cargo.toml | 1 + embassy-executor/tests/ui.rs | 13 +- .../tests/ui/bad_return_impl_future.rs | 9 ++ .../tests/ui/bad_return_impl_future.stderr | 120 ++++++++++++++++++ .../tests/ui/bad_return_impl_future_nightly.rs | 9 ++ .../tests/ui/bad_return_impl_future_nightly.stderr | 10 ++ embassy-executor/tests/ui/bad_return_impl_trait.rs | 9 -- .../tests/ui/bad_return_impl_trait.stderr | 120 ------------------ .../tests/ui/bad_return_impl_trait_nightly.rs | 9 -- .../tests/ui/bad_return_impl_trait_nightly.stderr | 10 -- embassy-executor/tests/ui/return_impl_send.rs | 6 + embassy-executor/tests/ui/return_impl_send.stderr | 137 +++++++++++++++++++++ .../tests/ui/return_impl_send_nightly.rs | 6 + .../tests/ui/return_impl_send_nightly.stderr | 10 ++ 14 files changed, 317 insertions(+), 152 deletions(-) create mode 100644 embassy-executor/tests/ui/bad_return_impl_future.rs create mode 100644 embassy-executor/tests/ui/bad_return_impl_future.stderr create mode 100644 embassy-executor/tests/ui/bad_return_impl_future_nightly.rs create mode 100644 embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr delete mode 100644 embassy-executor/tests/ui/bad_return_impl_trait.rs delete mode 100644 embassy-executor/tests/ui/bad_return_impl_trait.stderr delete mode 100644 embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs delete mode 100644 embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr create mode 100644 embassy-executor/tests/ui/return_impl_send.rs create mode 100644 embassy-executor/tests/ui/return_impl_send.stderr create mode 100644 embassy-executor/tests/ui/return_impl_send_nightly.rs create mode 100644 embassy-executor/tests/ui/return_impl_send_nightly.stderr (limited to 'embassy-executor') diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index f014ccf30..2dbf2c29a 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -59,6 +59,7 @@ avr-device = { version = "0.7.0", optional = true } critical-section = { version = "1.1", features = ["std"] } trybuild = "1.0" embassy-sync = { path = "../embassy-sync" } +rustversion = "1.0.21" [features] diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs index ed8228e27..c4a1a601c 100644 --- a/embassy-executor/tests/ui.rs +++ b/embassy-executor/tests/ui.rs @@ -17,10 +17,15 @@ fn ui() { t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); t.compile_fail("tests/ui/not_async.rs"); - // #[cfg(not(feature = "nightly"))] // output differs on stable and nightly - // t.compile_fail("tests/ui/bad_return_impl_trait.rs"); - #[cfg(feature = "nightly")] - t.compile_fail("tests/ui/bad_return_impl_trait_nightly.rs"); + if rustversion::cfg!(stable) { + // output is slightly different on nightly + t.compile_fail("tests/ui/bad_return_impl_future.rs"); + t.compile_fail("tests/ui/return_impl_send.rs"); + } + if cfg!(feature = "nightly") { + t.compile_fail("tests/ui/bad_return_impl_future_nightly.rs"); + t.compile_fail("tests/ui/return_impl_send_nightly.rs"); + } t.compile_fail("tests/ui/self_ref.rs"); t.compile_fail("tests/ui/self.rs"); t.compile_fail("tests/ui/type_error.rs"); diff --git a/embassy-executor/tests/ui/bad_return_impl_future.rs b/embassy-executor/tests/ui/bad_return_impl_future.rs new file mode 100644 index 000000000..baaa7dc5a --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_future.rs @@ -0,0 +1,9 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] +use core::future::Future; + +#[embassy_executor::task] +fn task() -> impl Future { + async { 5 } +} + +fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_future.stderr b/embassy-executor/tests/ui/bad_return_impl_future.stderr new file mode 100644 index 000000000..2980fd18b --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_future.stderr @@ -0,0 +1,120 @@ +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_size` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_align` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_new` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `__task_pool_get` + --> tests/ui/bad_return_impl_future.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/embassy-executor/tests/ui/bad_return_impl_future_nightly.rs b/embassy-executor/tests/ui/bad_return_impl_future_nightly.rs new file mode 100644 index 000000000..baaa7dc5a --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_future_nightly.rs @@ -0,0 +1,9 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] +use core::future::Future; + +#[embassy_executor::task] +fn task() -> impl Future { + async { 5 } +} + +fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr new file mode 100644 index 000000000..73ceb989d --- /dev/null +++ b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr @@ -0,0 +1,10 @@ +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future_nightly.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` + | + = note: use `async fn` or change the return type to `impl Future` + = help: the following other types implement trait `TaskReturnValue`: + () + ! as _export::HasOutput>::Output diff --git a/embassy-executor/tests/ui/bad_return_impl_trait.rs b/embassy-executor/tests/ui/bad_return_impl_trait.rs deleted file mode 100644 index baaa7dc5a..000000000 --- a/embassy-executor/tests/ui/bad_return_impl_trait.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] -use core::future::Future; - -#[embassy_executor::task] -fn task() -> impl Future { - async { 5 } -} - -fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_trait.stderr b/embassy-executor/tests/ui/bad_return_impl_trait.stderr deleted file mode 100644 index 9e2df353e..000000000 --- a/embassy-executor/tests/ui/bad_return_impl_trait.stderr +++ /dev/null @@ -1,120 +0,0 @@ -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:5:4 - | -4 | #[embassy_executor::task] - | ------------------------- required by a bound introduced by this call -5 | fn task() -> impl Future { - | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_size` - --> src/lib.rs - | - | pub const fn task_pool_size(_: F) -> usize - | -------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^ required by this bound in `task_pool_size` - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_size` - --> src/lib.rs - | - | pub const fn task_pool_size(_: F) -> usize - | -------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:5:4 - | -4 | #[embassy_executor::task] - | ------------------------- required by a bound introduced by this call -5 | fn task() -> impl Future { - | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_align` - --> src/lib.rs - | - | pub const fn task_pool_align(_: F) -> usize - | --------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^ required by this bound in `task_pool_align` - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_align` - --> src/lib.rs - | - | pub const fn task_pool_align(_: F) -> usize - | --------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:5:4 - | -4 | #[embassy_executor::task] - | ------------------------- required by a bound introduced by this call -5 | fn task() -> impl Future { - | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_new` - --> src/lib.rs - | - | pub const fn task_pool_new(_: F) -> TaskPool - | ------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^ required by this bound in `task_pool_new` - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_new` - --> src/lib.rs - | - | pub const fn task_pool_new(_: F) -> TaskPool - | ------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: task function futures must resolve to `()` - --> tests/ui/bad_return_impl_trait.rs:5:4 - | -4 | #[embassy_executor::task] - | ------------------------- required by a bound introduced by this call -5 | fn task() -> impl Future { - | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `__task_pool_get` - --> tests/ui/bad_return_impl_trait.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs deleted file mode 100644 index baaa7dc5a..000000000 --- a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] -use core::future::Future; - -#[embassy_executor::task] -fn task() -> impl Future { - async { 5 } -} - -fn main() {} diff --git a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr deleted file mode 100644 index a51251bb8..000000000 --- a/embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error[E0277]: task futures must resolve to `()` or `!` - --> tests/ui/bad_return_impl_trait_nightly.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` - | - = note: use `async fn` or change the return type to `impl Future` - = help: the following other types implement trait `TaskReturnValue`: - () - ! as _export::HasOutput>::Output diff --git a/embassy-executor/tests/ui/return_impl_send.rs b/embassy-executor/tests/ui/return_impl_send.rs new file mode 100644 index 000000000..6ddb0e722 --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_send.rs @@ -0,0 +1,6 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] + +#[embassy_executor::task] +fn task() -> impl Send {} + +fn main() {} diff --git a/embassy-executor/tests/ui/return_impl_send.stderr b/embassy-executor/tests/ui/return_impl_send.stderr new file mode 100644 index 000000000..7e3e468b8 --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_send.stderr @@ -0,0 +1,137 @@ +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:4:4 + | +3 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +4 | fn task() -> impl Send {} + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_size` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_size` + --> src/lib.rs + | + | pub const fn task_pool_size(_: F) -> usize + | -------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:4:4 + | +3 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +4 | fn task() -> impl Send {} + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_align` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_align` + --> src/lib.rs + | + | pub const fn task_pool_align(_: F) -> usize + | --------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:4:4 + | +3 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +4 | fn task() -> impl Send {} + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_new` + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs + | + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/return_impl_send.rs:4:4 + | +3 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +4 | fn task() -> impl Send {} + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `__task_pool_get` + --> tests/ui/return_impl_send.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: `impl Send` is not a future + --> tests/ui/return_impl_send.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Send` is not a future + | + = help: the trait `Future` is not implemented for `impl Send` +note: required by a bound in `TaskPool::::_spawn_async_fn` + --> src/raw/mod.rs + | + | impl TaskPool { + | ^^^^^^ required by this bound in `TaskPool::::_spawn_async_fn` +... + | pub unsafe fn _spawn_async_fn(&'static self, future: FutFn) -> SpawnToken + | --------------- required by a bound in this associated function + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/embassy-executor/tests/ui/return_impl_send_nightly.rs b/embassy-executor/tests/ui/return_impl_send_nightly.rs new file mode 100644 index 000000000..6ddb0e722 --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_send_nightly.rs @@ -0,0 +1,6 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] + +#[embassy_executor::task] +fn task() -> impl Send {} + +fn main() {} diff --git a/embassy-executor/tests/ui/return_impl_send_nightly.stderr b/embassy-executor/tests/ui/return_impl_send_nightly.stderr new file mode 100644 index 000000000..de9ba6243 --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_send_nightly.stderr @@ -0,0 +1,10 @@ +error[E0277]: `impl Send` is not a future + --> tests/ui/return_impl_send_nightly.rs:3:1 + | +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `impl Send` is not a future + | return type was inferred to be `impl Send` here + | + = help: the trait `Future` is not implemented for `impl Send` -- cgit From 72248a601a9ea28ac696f186e2cbe4c2f128a133 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 29 Jun 2025 22:37:11 +0200 Subject: Update Rust nightly, stable. --- embassy-executor/build_common.rs | 32 ----------- .../tests/ui/bad_return_impl_future.stderr | 32 +++++------ embassy-executor/tests/ui/return_impl_send.stderr | 64 +++++++++++----------- 3 files changed, 48 insertions(+), 80 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/build_common.rs b/embassy-executor/build_common.rs index b15a8369f..4f24e6d37 100644 --- a/embassy-executor/build_common.rs +++ b/embassy-executor/build_common.rs @@ -92,35 +92,3 @@ pub fn set_target_cfgs(cfgs: &mut CfgSet) { cfgs.set("has_fpu", target.ends_with("-eabihf")); } - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub struct CompilerDate { - year: u16, - month: u8, - day: u8, -} - -impl CompilerDate { - fn parse(date: &str) -> Option { - let mut parts = date.split('-'); - let year = parts.next()?.parse().ok()?; - let month = parts.next()?.parse().ok()?; - let day = parts.next()?.parse().ok()?; - Some(Self { year, month, day }) - } -} - -impl PartialEq<&str> for CompilerDate { - fn eq(&self, other: &&str) -> bool { - let Some(other) = Self::parse(other) else { - return false; - }; - self.eq(&other) - } -} - -impl PartialOrd<&str> for CompilerDate { - fn partial_cmp(&self, other: &&str) -> Option { - Self::parse(other).map(|other| self.cmp(&other)) - } -} diff --git a/embassy-executor/tests/ui/bad_return_impl_future.stderr b/embassy-executor/tests/ui/bad_return_impl_future.stderr index 2980fd18b..57f147714 100644 --- a/embassy-executor/tests/ui/bad_return_impl_future.stderr +++ b/embassy-executor/tests/ui/bad_return_impl_future.stderr @@ -68,6 +68,22 @@ note: required by a bound in `task_pool_align` | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: task futures must resolve to `()` or `!` + --> tests/ui/bad_return_impl_future.rs:5:4 + | +4 | #[embassy_executor::task] + | ------------------------- required by a bound introduced by this call +5 | fn task() -> impl Future { + | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` + | + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `__task_pool_get` + --> tests/ui/bad_return_impl_future.rs:4:1 + | +4 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0277]: task futures must resolve to `()` or `!` --> tests/ui/bad_return_impl_future.rs:5:4 | @@ -102,19 +118,3 @@ note: required by a bound in `task_pool_new` | F: TaskFn, | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: task futures must resolve to `()` or `!` - --> tests/ui/bad_return_impl_future.rs:5:4 - | -4 | #[embassy_executor::task] - | ------------------------- required by a bound introduced by this call -5 | fn task() -> impl Future { - | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future {__task_task}` - | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `__task_pool_get` - --> tests/ui/bad_return_impl_future.rs:4:1 - | -4 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/embassy-executor/tests/ui/return_impl_send.stderr b/embassy-executor/tests/ui/return_impl_send.stderr index 7e3e468b8..cd693af2b 100644 --- a/embassy-executor/tests/ui/return_impl_send.stderr +++ b/embassy-executor/tests/ui/return_impl_send.stderr @@ -77,30 +77,28 @@ error[E0277]: task futures must resolve to `()` or `!` | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_new` - --> src/lib.rs +note: required by a bound in `__task_pool_get` + --> tests/ui/return_impl_send.rs:3:1 | - | pub const fn task_pool_new(_: F) -> TaskPool - | ------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^ required by this bound in `task_pool_new` +3 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: task futures must resolve to `()` or `!` +error[E0277]: `impl Send` is not a future --> tests/ui/return_impl_send.rs:3:1 | 3 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Send` is not a future | - = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `task_pool_new` - --> src/lib.rs + = help: the trait `Future` is not implemented for `impl Send` +note: required by a bound in `TaskPool::::_spawn_async_fn` + --> src/raw/mod.rs | - | pub const fn task_pool_new(_: F) -> TaskPool - | ------------- required by a bound in this function - | where - | F: TaskFn, - | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` + | impl TaskPool { + | ^^^^^^ required by this bound in `TaskPool::::_spawn_async_fn` +... + | pub unsafe fn _spawn_async_fn(&'static self, future: FutFn) -> SpawnToken + | --------------- required by a bound in this associated function = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: task futures must resolve to `()` or `!` @@ -112,26 +110,28 @@ error[E0277]: task futures must resolve to `()` or `!` | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | = note: use `async fn` or change the return type to `impl Future` -note: required by a bound in `__task_pool_get` - --> tests/ui/return_impl_send.rs:3:1 +note: required by a bound in `task_pool_new` + --> src/lib.rs | -3 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` - = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^ required by this bound in `task_pool_new` -error[E0277]: `impl Send` is not a future +error[E0277]: task futures must resolve to `()` or `!` --> tests/ui/return_impl_send.rs:3:1 | 3 | #[embassy_executor::task] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Send` is not a future + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | - = help: the trait `Future` is not implemented for `impl Send` -note: required by a bound in `TaskPool::::_spawn_async_fn` - --> src/raw/mod.rs + = note: use `async fn` or change the return type to `impl Future` +note: required by a bound in `task_pool_new` + --> src/lib.rs | - | impl TaskPool { - | ^^^^^^ required by this bound in `TaskPool::::_spawn_async_fn` -... - | pub unsafe fn _spawn_async_fn(&'static self, future: FutFn) -> SpawnToken - | --------------- required by a bound in this associated function + | pub const fn task_pool_new(_: F) -> TaskPool + | ------------- required by a bound in this function + | where + | F: TaskFn, + | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit From b861dd172829c5b34e95644287544e090dd9f568 Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Sat, 5 Jul 2025 18:27:46 +0200 Subject: embassy-executor: rtos-trace: fix task naming for new tasks Tasks that are spawned after starting SystemViewer were not named. This change ensures that tasks spawned while SystemViewer is running will be properly named, too. Signed-off-by: Florian Grandel --- embassy-executor/src/raw/trace.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/raw/trace.rs b/embassy-executor/src/raw/trace.rs index 6c9cfda25..aa27ab37e 100644 --- a/embassy-executor/src/raw/trace.rs +++ b/embassy-executor/src/raw/trace.rs @@ -283,7 +283,17 @@ pub(crate) fn task_new(executor: &SyncExecutor, task: &TaskRef) { } #[cfg(feature = "rtos-trace")] - rtos_trace::trace::task_new(task.as_ptr() as u32); + { + rtos_trace::trace::task_new(task.as_ptr() as u32); + let name = task.name().unwrap_or("unnamed task\0"); + let info = rtos_trace::TaskInfo { + name, + priority: 0, + stack_base: 0, + stack_size: 0, + }; + rtos_trace::trace::task_send_info(task.id(), info); + } #[cfg(feature = "rtos-trace")] TASK_TRACKER.add(*task); -- cgit From 2fe2a0cf9c15bf7e84134cd7fec48017bb0a0db7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 8 Jul 2025 20:19:01 +0200 Subject: excutor: fix Send unsoundness with `-> impl Future` tasks. --- embassy-executor/tests/ui.rs | 2 ++ .../tests/ui/return_impl_future_nonsend.rs | 21 +++++++++++ .../tests/ui/return_impl_future_nonsend.stderr | 17 +++++++++ embassy-executor/tests/ui/return_impl_send.stderr | 8 ++--- embassy-executor/tests/ui/spawn_nonsend.rs | 16 +++++++++ embassy-executor/tests/ui/spawn_nonsend.stderr | 41 ++++++++++++++++++++++ 6 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 embassy-executor/tests/ui/return_impl_future_nonsend.rs create mode 100644 embassy-executor/tests/ui/return_impl_future_nonsend.stderr create mode 100644 embassy-executor/tests/ui/spawn_nonsend.rs create mode 100644 embassy-executor/tests/ui/spawn_nonsend.stderr (limited to 'embassy-executor') diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs index c4a1a601c..7757775ee 100644 --- a/embassy-executor/tests/ui.rs +++ b/embassy-executor/tests/ui.rs @@ -17,6 +17,8 @@ fn ui() { t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); t.compile_fail("tests/ui/not_async.rs"); + t.compile_fail("tests/ui/spawn_nonsend.rs"); + t.compile_fail("tests/ui/return_impl_future_nonsend.rs"); if rustversion::cfg!(stable) { // output is slightly different on nightly t.compile_fail("tests/ui/bad_return_impl_future.rs"); diff --git a/embassy-executor/tests/ui/return_impl_future_nonsend.rs b/embassy-executor/tests/ui/return_impl_future_nonsend.rs new file mode 100644 index 000000000..b8c184b21 --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_future_nonsend.rs @@ -0,0 +1,21 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] + +use core::future::Future; + +use embassy_executor::SendSpawner; + +#[embassy_executor::task] +fn task() -> impl Future { + // runs in spawning thread + let non_send: *mut () = core::ptr::null_mut(); + async move { + // runs in executor thread + println!("{}", non_send as usize); + } +} + +fn send_spawn(s: SendSpawner) { + s.spawn(task()).unwrap(); +} + +fn main() {} diff --git a/embassy-executor/tests/ui/return_impl_future_nonsend.stderr b/embassy-executor/tests/ui/return_impl_future_nonsend.stderr new file mode 100644 index 000000000..8aeb9738a --- /dev/null +++ b/embassy-executor/tests/ui/return_impl_future_nonsend.stderr @@ -0,0 +1,17 @@ +error: future cannot be sent between threads safely + --> tests/ui/return_impl_future_nonsend.rs:18:13 + | +18 | s.spawn(task()).unwrap(); + | ^^^^^^ future created by async block is not `Send` + | + = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()` +note: captured value is not `Send` + --> tests/ui/return_impl_future_nonsend.rs:13:24 + | +13 | println!("{}", non_send as usize); + | ^^^^^^^^ has type `*mut ()` which is not `Send` +note: required by a bound in `SendSpawner::spawn` + --> src/spawner.rs + | + | pub fn spawn(&self, token: SpawnToken) -> Result<(), SpawnError> { + | ^^^^ required by this bound in `SendSpawner::spawn` diff --git a/embassy-executor/tests/ui/return_impl_send.stderr b/embassy-executor/tests/ui/return_impl_send.stderr index cd693af2b..759be1cde 100644 --- a/embassy-executor/tests/ui/return_impl_send.stderr +++ b/embassy-executor/tests/ui/return_impl_send.stderr @@ -91,14 +91,14 @@ error[E0277]: `impl Send` is not a future | ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Send` is not a future | = help: the trait `Future` is not implemented for `impl Send` -note: required by a bound in `TaskPool::::_spawn_async_fn` +note: required by a bound in `TaskPool::::spawn` --> src/raw/mod.rs | | impl TaskPool { - | ^^^^^^ required by this bound in `TaskPool::::_spawn_async_fn` + | ^^^^^^ required by this bound in `TaskPool::::spawn` ... - | pub unsafe fn _spawn_async_fn(&'static self, future: FutFn) -> SpawnToken - | --------------- required by a bound in this associated function + | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken { + | ----- required by a bound in this associated function = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: task futures must resolve to `()` or `!` diff --git a/embassy-executor/tests/ui/spawn_nonsend.rs b/embassy-executor/tests/ui/spawn_nonsend.rs new file mode 100644 index 000000000..4c4cc7697 --- /dev/null +++ b/embassy-executor/tests/ui/spawn_nonsend.rs @@ -0,0 +1,16 @@ +#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] + +use core::future::Future; + +use embassy_executor::SendSpawner; + +#[embassy_executor::task] +async fn task(non_send: *mut ()) { + println!("{}", non_send as usize); +} + +fn send_spawn(s: SendSpawner) { + s.spawn(task(core::ptr::null_mut())).unwrap(); +} + +fn main() {} diff --git a/embassy-executor/tests/ui/spawn_nonsend.stderr b/embassy-executor/tests/ui/spawn_nonsend.stderr new file mode 100644 index 000000000..2a06c8b94 --- /dev/null +++ b/embassy-executor/tests/ui/spawn_nonsend.stderr @@ -0,0 +1,41 @@ +warning: unused import: `core::future::Future` + --> tests/ui/spawn_nonsend.rs:3:5 + | +3 | use core::future::Future; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0277]: `*mut ()` cannot be sent between threads safely + --> tests/ui/spawn_nonsend.rs:13:13 + | +7 | #[embassy_executor::task] + | ------------------------- within this `impl Sized` +... +13 | s.spawn(task(core::ptr::null_mut())).unwrap(); + | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut ()` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()` +note: required because it's used within this closure + --> tests/ui/spawn_nonsend.rs:7:1 + | +7 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required because it appears within the type `impl Sized` + --> src/raw/mod.rs + | + | pub unsafe fn _spawn_async_fn(&'static self, future: FutFn) -> SpawnToken + | ^^^^^^^^^^ +note: required because it appears within the type `impl Sized` + --> tests/ui/spawn_nonsend.rs:7:1 + | +7 | #[embassy_executor::task] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `SendSpawner::spawn` + --> src/spawner.rs + | + | pub fn spawn(&self, token: SpawnToken) -> Result<(), SpawnError> { + | ^^^^ required by this bound in `SendSpawner::spawn` + = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit From 0c136c7b050ded4bf660ea7a50381698ab9d5f09 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 8 Jul 2025 22:39:53 +0200 Subject: executor: mark Spawner::for_current_executor() as unsafe. It's unsound with manually-created Contexts, see https://github.com/embassy-rs/embassy/issues/4379 --- embassy-executor/src/spawner.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs index 522d97db3..2909d19a0 100644 --- a/embassy-executor/src/spawner.rs +++ b/embassy-executor/src/spawner.rs @@ -122,10 +122,26 @@ impl Spawner { /// This function is `async` just to get access to the current async /// context. It returns instantly, it does not block/yield. /// + /// Using this method is discouraged due to it being unsafe. Consider the following + /// alternatives instead: + /// + /// - Pass the initial `Spawner` as an argument to tasks. Note that it's `Copy`, so you can + /// make as many copies of it as you want. + /// - Use `SendSpawner::for_current_executor()` instead, which is safe but can only be used + /// if task arguments are `Send`. + /// + /// The only case where using this method is absolutely required is obtaining the `Spawner` + /// for an `InterruptExecutor`. + /// + /// # Safety + /// + /// You must only execute this with an async `Context` created by the Embassy executor. + /// You must not execute it with manually-created `Context`s. + /// /// # Panics /// /// Panics if the current executor is not an Embassy executor. - pub fn for_current_executor() -> impl Future { + pub unsafe fn for_current_executor() -> impl Future { poll_fn(|cx| { let task = raw::task_from_waker(cx.waker()); let executor = unsafe { -- cgit From 1c515937ff69cf2358118e13a9a70178dd7a99a0 Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Wed, 11 Jun 2025 09:47:25 +0200 Subject: prepare changelog for `embassy-executor` v0.8.0 --- embassy-executor/CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'embassy-executor') diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 608c67724..19e41e3e7 100644 --- a/embassy-executor/CHANGELOG.md +++ b/embassy-executor/CHANGELOG.md @@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +- Added `SpawnToken::id` +- Task pools are now statically allocated on stable rust. All `task-arena-size-*` features have been removed and are no longer necessary. +- New trace hooks: `_embassy_trace_poll_start` & `_embassy_trace_task_end` +- Added task naming capability to tracing infrastructure +- Added `Executor::id` & `Spawner::executor_id` +- Disable `critical-section/std` for arch-std +- Added possibility to select an executor in `#[embassy_executor::main]` +- Fix AVR executor +- executor: Make state implementations and their conditions match - Added support for Cortex-A and Cortex-R +- Added support for `-> impl Future` in `#[task]` +- Fixed `Send` unsoundness with `-> impl Future` tasks +- Marked `Spawner::for_current_executor` as `unsafe` ## 0.7.0 - 2025-01-02 -- cgit From a52ca758ac84af5b9fafa9f6cc0562495a796ffd Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Wed, 11 Jun 2025 09:48:37 +0200 Subject: `embassy-executor`: add release automation using `cargo-release` this requires you to install [`cargo-release`]. note that this does not include a URL pointing to the diff on GitHub as is usually done in changelogs since `embassy` is a mono-repo and the GH UI doesn't offer a commit view per folder (see the [GH feature request] for this). [`cargo-release`]: https://crates.io/crates/cargo-release [GH feature request]: https://github.com/orgs/community/discussions/162131 --- embassy-executor/CHANGELOG.md | 3 ++- embassy-executor/release.toml | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 embassy-executor/release.toml (limited to 'embassy-executor') diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 19e41e3e7..914863a83 100644 --- a/embassy-executor/CHANGELOG.md +++ b/embassy-executor/CHANGELOG.md @@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## unreleased + +## Unreleased - ReleaseDate - Added `SpawnToken::id` - Task pools are now statically allocated on stable rust. All `task-arena-size-*` features have been removed and are no longer necessary. diff --git a/embassy-executor/release.toml b/embassy-executor/release.toml new file mode 100644 index 000000000..fb6feaf21 --- /dev/null +++ b/embassy-executor/release.toml @@ -0,0 +1,5 @@ +pre-release-replacements = [ + {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, + {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, + {file="CHANGELOG.md", search="", replace="\n## Unreleased - ReleaseDate\n", exactly=1}, +] -- cgit