diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-06-22 21:27:56 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-22 21:27:56 +0000 |
| commit | 8a23a4dfa4229af502f07798674842a07b4df7ba (patch) | |
| tree | 75dfa8c069eabd671171dbcc1662e5bb8bbdde4d | |
| parent | bf3170ed386187ef7ef19264a9cf8cba99dcb8b6 (diff) | |
| parent | 3cef4f0c04a1f0f56c84950d8fd408979299fa50 (diff) | |
Merge pull request #4266 from 0e4ef622/task-rpit
Allow `-> impl Future<Output = ()>` in #[task]
| -rw-r--r-- | embassy-executor-macros/src/macros/task.rs | 34 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 1 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 51 | ||||
| -rw-r--r-- | embassy-executor/tests/test.rs | 36 | ||||
| -rw-r--r-- | embassy-executor/tests/ui.rs | 9 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_future.rs | 9 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_future.stderr | 120 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_future_nightly.rs | 9 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr | 10 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_send.rs | 6 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_send.stderr | 137 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_send_nightly.rs | 6 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_send_nightly.stderr | 10 |
13 files changed, 421 insertions, 17 deletions
diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 91d6beee8..91bf8e940 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs | |||
| @@ -51,7 +51,11 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 51 | .embassy_executor | 51 | .embassy_executor |
| 52 | .unwrap_or(Expr::Verbatim(TokenStream::from_str("::embassy_executor").unwrap())); | 52 | .unwrap_or(Expr::Verbatim(TokenStream::from_str("::embassy_executor").unwrap())); |
| 53 | 53 | ||
| 54 | if f.sig.asyncness.is_none() { | 54 | let returns_impl_trait = match &f.sig.output { |
| 55 | ReturnType::Type(_, ty) => matches!(**ty, Type::ImplTrait(_)), | ||
| 56 | _ => false, | ||
| 57 | }; | ||
| 58 | if f.sig.asyncness.is_none() && !returns_impl_trait { | ||
| 55 | error(&mut errors, &f.sig, "task functions must be async"); | 59 | error(&mut errors, &f.sig, "task functions must be async"); |
| 56 | } | 60 | } |
| 57 | if !f.sig.generics.params.is_empty() { | 61 | if !f.sig.generics.params.is_empty() { |
| @@ -66,17 +70,19 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 66 | if !f.sig.variadic.is_none() { | 70 | if !f.sig.variadic.is_none() { |
| 67 | error(&mut errors, &f.sig, "task functions must not be variadic"); | 71 | error(&mut errors, &f.sig, "task functions must not be variadic"); |
| 68 | } | 72 | } |
| 69 | match &f.sig.output { | 73 | if f.sig.asyncness.is_some() { |
| 70 | ReturnType::Default => {} | 74 | match &f.sig.output { |
| 71 | ReturnType::Type(_, ty) => match &**ty { | 75 | ReturnType::Default => {} |
| 72 | Type::Tuple(tuple) if tuple.elems.is_empty() => {} | 76 | ReturnType::Type(_, ty) => match &**ty { |
| 73 | Type::Never(_) => {} | 77 | Type::Tuple(tuple) if tuple.elems.is_empty() => {} |
| 74 | _ => error( | 78 | Type::Never(_) => {} |
| 75 | &mut errors, | 79 | _ => error( |
| 76 | &f.sig, | 80 | &mut errors, |
| 77 | "task functions must either not return a value, return `()` or return `!`", | 81 | &f.sig, |
| 78 | ), | 82 | "task functions must either not return a value, return `()` or return `!`", |
| 79 | }, | 83 | ), |
| 84 | }, | ||
| 85 | } | ||
| 80 | } | 86 | } |
| 81 | 87 | ||
| 82 | let mut args = Vec::new(); | 88 | let mut args = Vec::new(); |
| @@ -128,12 +134,12 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 128 | #[cfg(feature = "nightly")] | 134 | #[cfg(feature = "nightly")] |
| 129 | let mut task_outer_body = quote! { | 135 | let mut task_outer_body = quote! { |
| 130 | trait _EmbassyInternalTaskTrait { | 136 | trait _EmbassyInternalTaskTrait { |
| 131 | type Fut: ::core::future::Future + 'static; | 137 | type Fut: ::core::future::Future<Output: #embassy_executor::_export::TaskReturnValue> + 'static; |
| 132 | fn construct(#fargs) -> Self::Fut; | 138 | fn construct(#fargs) -> Self::Fut; |
| 133 | } | 139 | } |
| 134 | 140 | ||
| 135 | impl _EmbassyInternalTaskTrait for () { | 141 | impl _EmbassyInternalTaskTrait for () { |
| 136 | type Fut = impl core::future::Future + 'static; | 142 | type Fut = impl core::future::Future<Output: #embassy_executor::_export::TaskReturnValue> + 'static; |
| 137 | fn construct(#fargs) -> Self::Fut { | 143 | fn construct(#fargs) -> Self::Fut { |
| 138 | #task_inner_ident(#(#full_args,)*) | 144 | #task_inner_ident(#(#full_args,)*) |
| 139 | } | 145 | } |
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 } | |||
| 59 | critical-section = { version = "1.1", features = ["std"] } | 59 | critical-section = { version = "1.1", features = ["std"] } |
| 60 | trybuild = "1.0" | 60 | trybuild = "1.0" |
| 61 | embassy-sync = { path = "../embassy-sync" } | 61 | embassy-sync = { path = "../embassy-sync" } |
| 62 | rustversion = "1.0.21" | ||
| 62 | 63 | ||
| 63 | [features] | 64 | [features] |
| 64 | 65 | ||
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index dfe420bab..e174a0594 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -65,8 +65,17 @@ pub mod _export { | |||
| 65 | 65 | ||
| 66 | use crate::raw::TaskPool; | 66 | use crate::raw::TaskPool; |
| 67 | 67 | ||
| 68 | trait TaskReturnValue {} | ||
| 69 | impl TaskReturnValue for () {} | ||
| 70 | impl TaskReturnValue for Never {} | ||
| 71 | |||
| 72 | #[diagnostic::on_unimplemented( | ||
| 73 | message = "task futures must resolve to `()` or `!`", | ||
| 74 | note = "use `async fn` or change the return type to `impl Future<Output = ()>`" | ||
| 75 | )] | ||
| 76 | #[allow(private_bounds)] | ||
| 68 | pub trait TaskFn<Args>: Copy { | 77 | pub trait TaskFn<Args>: Copy { |
| 69 | type Fut: Future + 'static; | 78 | type Fut: Future<Output: TaskReturnValue> + 'static; |
| 70 | } | 79 | } |
| 71 | 80 | ||
| 72 | macro_rules! task_fn_impl { | 81 | macro_rules! task_fn_impl { |
| @@ -74,7 +83,7 @@ pub mod _export { | |||
| 74 | impl<F, Fut, $($Tn,)*> TaskFn<($($Tn,)*)> for F | 83 | impl<F, Fut, $($Tn,)*> TaskFn<($($Tn,)*)> for F |
| 75 | where | 84 | where |
| 76 | F: Copy + FnOnce($($Tn,)*) -> Fut, | 85 | F: Copy + FnOnce($($Tn,)*) -> Fut, |
| 77 | Fut: Future + 'static, | 86 | Fut: Future<Output: TaskReturnValue> + 'static, |
| 78 | { | 87 | { |
| 79 | type Fut = Fut; | 88 | type Fut = Fut; |
| 80 | } | 89 | } |
| @@ -205,4 +214,42 @@ pub mod _export { | |||
| 205 | Align268435456: 268435456, | 214 | Align268435456: 268435456, |
| 206 | Align536870912: 536870912, | 215 | Align536870912: 536870912, |
| 207 | ); | 216 | ); |
| 217 | |||
| 218 | #[allow(dead_code)] | ||
| 219 | trait HasOutput { | ||
| 220 | type Output; | ||
| 221 | } | ||
| 222 | |||
| 223 | impl<O> HasOutput for fn() -> O { | ||
| 224 | type Output = O; | ||
| 225 | } | ||
| 226 | |||
| 227 | #[allow(dead_code)] | ||
| 228 | type Never = <fn() -> ! as HasOutput>::Output; | ||
| 229 | } | ||
| 230 | |||
| 231 | /// Implementation details for embassy macros. | ||
| 232 | /// Do not use. Used for macros and HALs only. Not covered by semver guarantees. | ||
| 233 | #[doc(hidden)] | ||
| 234 | #[cfg(feature = "nightly")] | ||
| 235 | pub mod _export { | ||
| 236 | #[diagnostic::on_unimplemented( | ||
| 237 | message = "task futures must resolve to `()` or `!`", | ||
| 238 | note = "use `async fn` or change the return type to `impl Future<Output = ()>`" | ||
| 239 | )] | ||
| 240 | pub trait TaskReturnValue {} | ||
| 241 | impl TaskReturnValue for () {} | ||
| 242 | impl TaskReturnValue for Never {} | ||
| 243 | |||
| 244 | #[allow(dead_code)] | ||
| 245 | trait HasOutput { | ||
| 246 | type Output; | ||
| 247 | } | ||
| 248 | |||
| 249 | impl<O> HasOutput for fn() -> O { | ||
| 250 | type Output = O; | ||
| 251 | } | ||
| 252 | |||
| 253 | #[allow(dead_code)] | ||
| 254 | type Never = <fn() -> ! as HasOutput>::Output; | ||
| 208 | } | 255 | } |
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 78c49c071..c1e7ec5d7 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] |
| 2 | #![cfg_attr(feature = "nightly", feature(never_type))] | ||
| 2 | 3 | ||
| 3 | use std::boxed::Box; | 4 | use std::boxed::Box; |
| 4 | use std::future::poll_fn; | 5 | use std::future::{poll_fn, Future}; |
| 5 | use std::sync::{Arc, Mutex}; | 6 | use std::sync::{Arc, Mutex}; |
| 6 | use std::task::Poll; | 7 | use std::task::Poll; |
| 7 | 8 | ||
| @@ -58,6 +59,39 @@ fn executor_task() { | |||
| 58 | trace.push("poll task1") | 59 | trace.push("poll task1") |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 62 | #[task] | ||
| 63 | async fn task2() -> ! { | ||
| 64 | panic!() | ||
| 65 | } | ||
| 66 | |||
| 67 | let (executor, trace) = setup(); | ||
| 68 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | ||
| 69 | |||
| 70 | unsafe { executor.poll() }; | ||
| 71 | unsafe { executor.poll() }; | ||
| 72 | |||
| 73 | assert_eq!( | ||
| 74 | trace.get(), | ||
| 75 | &[ | ||
| 76 | "pend", // spawning a task pends the executor | ||
| 77 | "poll task1", // poll only once. | ||
| 78 | ] | ||
| 79 | ) | ||
| 80 | } | ||
| 81 | |||
| 82 | #[test] | ||
| 83 | fn executor_task_rpit() { | ||
| 84 | #[task] | ||
| 85 | fn task1(trace: Trace) -> impl Future<Output = ()> { | ||
| 86 | async move { trace.push("poll task1") } | ||
| 87 | } | ||
| 88 | |||
| 89 | #[cfg(feature = "nightly")] | ||
| 90 | #[task] | ||
| 91 | fn task2() -> impl Future<Output = !> { | ||
| 92 | async { panic!() } | ||
| 93 | } | ||
| 94 | |||
| 61 | let (executor, trace) = setup(); | 95 | let (executor, trace) = setup(); |
| 62 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | 96 | executor.spawner().spawn(task1(trace.clone())).unwrap(); |
| 63 | 97 | ||
diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs index 278a4b903..c4a1a601c 100644 --- a/embassy-executor/tests/ui.rs +++ b/embassy-executor/tests/ui.rs | |||
| @@ -17,6 +17,15 @@ fn ui() { | |||
| 17 | t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); | 17 | t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); |
| 18 | t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); | 18 | t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); |
| 19 | t.compile_fail("tests/ui/not_async.rs"); | 19 | t.compile_fail("tests/ui/not_async.rs"); |
| 20 | if rustversion::cfg!(stable) { | ||
| 21 | // output is slightly different on nightly | ||
| 22 | t.compile_fail("tests/ui/bad_return_impl_future.rs"); | ||
| 23 | t.compile_fail("tests/ui/return_impl_send.rs"); | ||
| 24 | } | ||
| 25 | if cfg!(feature = "nightly") { | ||
| 26 | t.compile_fail("tests/ui/bad_return_impl_future_nightly.rs"); | ||
| 27 | t.compile_fail("tests/ui/return_impl_send_nightly.rs"); | ||
| 28 | } | ||
| 20 | t.compile_fail("tests/ui/self_ref.rs"); | 29 | t.compile_fail("tests/ui/self_ref.rs"); |
| 21 | t.compile_fail("tests/ui/self.rs"); | 30 | t.compile_fail("tests/ui/self.rs"); |
| 22 | t.compile_fail("tests/ui/type_error.rs"); | 31 | 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 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | use core::future::Future; | ||
| 3 | |||
| 4 | #[embassy_executor::task] | ||
| 5 | fn task() -> impl Future<Output = u32> { | ||
| 6 | async { 5 } | ||
| 7 | } | ||
| 8 | |||
| 9 | 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 @@ | |||
| 1 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 2 | --> tests/ui/bad_return_impl_future.rs:5:4 | ||
| 3 | | | ||
| 4 | 4 | #[embassy_executor::task] | ||
| 5 | | ------------------------- required by a bound introduced by this call | ||
| 6 | 5 | fn task() -> impl Future<Output = u32> { | ||
| 7 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 8 | | | ||
| 9 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 10 | note: required by a bound in `task_pool_size` | ||
| 11 | --> src/lib.rs | ||
| 12 | | | ||
| 13 | | pub const fn task_pool_size<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 14 | | -------------- required by a bound in this function | ||
| 15 | | where | ||
| 16 | | F: TaskFn<Args, Fut = Fut>, | ||
| 17 | | ^^^^^^^^^ required by this bound in `task_pool_size` | ||
| 18 | |||
| 19 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 20 | --> tests/ui/bad_return_impl_future.rs:4:1 | ||
| 21 | | | ||
| 22 | 4 | #[embassy_executor::task] | ||
| 23 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 24 | | | ||
| 25 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 26 | note: required by a bound in `task_pool_size` | ||
| 27 | --> src/lib.rs | ||
| 28 | | | ||
| 29 | | pub const fn task_pool_size<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 30 | | -------------- required by a bound in this function | ||
| 31 | | where | ||
| 32 | | F: TaskFn<Args, Fut = Fut>, | ||
| 33 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` | ||
| 34 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 35 | |||
| 36 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 37 | --> tests/ui/bad_return_impl_future.rs:5:4 | ||
| 38 | | | ||
| 39 | 4 | #[embassy_executor::task] | ||
| 40 | | ------------------------- required by a bound introduced by this call | ||
| 41 | 5 | fn task() -> impl Future<Output = u32> { | ||
| 42 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 43 | | | ||
| 44 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 45 | note: required by a bound in `task_pool_align` | ||
| 46 | --> src/lib.rs | ||
| 47 | | | ||
| 48 | | pub const fn task_pool_align<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 49 | | --------------- required by a bound in this function | ||
| 50 | | where | ||
| 51 | | F: TaskFn<Args, Fut = Fut>, | ||
| 52 | | ^^^^^^^^^ required by this bound in `task_pool_align` | ||
| 53 | |||
| 54 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 55 | --> tests/ui/bad_return_impl_future.rs:4:1 | ||
| 56 | | | ||
| 57 | 4 | #[embassy_executor::task] | ||
| 58 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 59 | | | ||
| 60 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 61 | note: required by a bound in `task_pool_align` | ||
| 62 | --> src/lib.rs | ||
| 63 | | | ||
| 64 | | pub const fn task_pool_align<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 65 | | --------------- required by a bound in this function | ||
| 66 | | where | ||
| 67 | | F: TaskFn<Args, Fut = Fut>, | ||
| 68 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` | ||
| 69 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 70 | |||
| 71 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 72 | --> tests/ui/bad_return_impl_future.rs:5:4 | ||
| 73 | | | ||
| 74 | 4 | #[embassy_executor::task] | ||
| 75 | | ------------------------- required by a bound introduced by this call | ||
| 76 | 5 | fn task() -> impl Future<Output = u32> { | ||
| 77 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 78 | | | ||
| 79 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 80 | note: required by a bound in `task_pool_new` | ||
| 81 | --> src/lib.rs | ||
| 82 | | | ||
| 83 | | pub const fn task_pool_new<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> TaskPool<Fut, POOL_SIZE> | ||
| 84 | | ------------- required by a bound in this function | ||
| 85 | | where | ||
| 86 | | F: TaskFn<Args, Fut = Fut>, | ||
| 87 | | ^^^^^^^^^ required by this bound in `task_pool_new` | ||
| 88 | |||
| 89 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 90 | --> tests/ui/bad_return_impl_future.rs:4:1 | ||
| 91 | | | ||
| 92 | 4 | #[embassy_executor::task] | ||
| 93 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 94 | | | ||
| 95 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 96 | note: required by a bound in `task_pool_new` | ||
| 97 | --> src/lib.rs | ||
| 98 | | | ||
| 99 | | pub const fn task_pool_new<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> TaskPool<Fut, POOL_SIZE> | ||
| 100 | | ------------- required by a bound in this function | ||
| 101 | | where | ||
| 102 | | F: TaskFn<Args, Fut = Fut>, | ||
| 103 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` | ||
| 104 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 105 | |||
| 106 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 107 | --> tests/ui/bad_return_impl_future.rs:5:4 | ||
| 108 | | | ||
| 109 | 4 | #[embassy_executor::task] | ||
| 110 | | ------------------------- required by a bound introduced by this call | ||
| 111 | 5 | fn task() -> impl Future<Output = u32> { | ||
| 112 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Future<Output = u32> {__task_task}` | ||
| 113 | | | ||
| 114 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 115 | note: required by a bound in `__task_pool_get` | ||
| 116 | --> tests/ui/bad_return_impl_future.rs:4:1 | ||
| 117 | | | ||
| 118 | 4 | #[embassy_executor::task] | ||
| 119 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` | ||
| 120 | = 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 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | use core::future::Future; | ||
| 3 | |||
| 4 | #[embassy_executor::task] | ||
| 5 | fn task() -> impl Future<Output = u32> { | ||
| 6 | async { 5 } | ||
| 7 | } | ||
| 8 | |||
| 9 | 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 @@ | |||
| 1 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 2 | --> tests/ui/bad_return_impl_future_nightly.rs:4:1 | ||
| 3 | | | ||
| 4 | 4 | #[embassy_executor::task] | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` | ||
| 6 | | | ||
| 7 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 8 | = help: the following other types implement trait `TaskReturnValue`: | ||
| 9 | () | ||
| 10 | <fn() -> ! 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 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | fn task() -> impl Send {} | ||
| 5 | |||
| 6 | 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 @@ | |||
| 1 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 2 | --> tests/ui/return_impl_send.rs:4:4 | ||
| 3 | | | ||
| 4 | 3 | #[embassy_executor::task] | ||
| 5 | | ------------------------- required by a bound introduced by this call | ||
| 6 | 4 | fn task() -> impl Send {} | ||
| 7 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 8 | | | ||
| 9 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 10 | note: required by a bound in `task_pool_size` | ||
| 11 | --> src/lib.rs | ||
| 12 | | | ||
| 13 | | pub const fn task_pool_size<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 14 | | -------------- required by a bound in this function | ||
| 15 | | where | ||
| 16 | | F: TaskFn<Args, Fut = Fut>, | ||
| 17 | | ^^^^^^^^^ required by this bound in `task_pool_size` | ||
| 18 | |||
| 19 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 20 | --> tests/ui/return_impl_send.rs:3:1 | ||
| 21 | | | ||
| 22 | 3 | #[embassy_executor::task] | ||
| 23 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 24 | | | ||
| 25 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 26 | note: required by a bound in `task_pool_size` | ||
| 27 | --> src/lib.rs | ||
| 28 | | | ||
| 29 | | pub const fn task_pool_size<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 30 | | -------------- required by a bound in this function | ||
| 31 | | where | ||
| 32 | | F: TaskFn<Args, Fut = Fut>, | ||
| 33 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_size` | ||
| 34 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 35 | |||
| 36 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 37 | --> tests/ui/return_impl_send.rs:4:4 | ||
| 38 | | | ||
| 39 | 3 | #[embassy_executor::task] | ||
| 40 | | ------------------------- required by a bound introduced by this call | ||
| 41 | 4 | fn task() -> impl Send {} | ||
| 42 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 43 | | | ||
| 44 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 45 | note: required by a bound in `task_pool_align` | ||
| 46 | --> src/lib.rs | ||
| 47 | | | ||
| 48 | | pub const fn task_pool_align<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 49 | | --------------- required by a bound in this function | ||
| 50 | | where | ||
| 51 | | F: TaskFn<Args, Fut = Fut>, | ||
| 52 | | ^^^^^^^^^ required by this bound in `task_pool_align` | ||
| 53 | |||
| 54 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 55 | --> tests/ui/return_impl_send.rs:3:1 | ||
| 56 | | | ||
| 57 | 3 | #[embassy_executor::task] | ||
| 58 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 59 | | | ||
| 60 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 61 | note: required by a bound in `task_pool_align` | ||
| 62 | --> src/lib.rs | ||
| 63 | | | ||
| 64 | | pub const fn task_pool_align<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize | ||
| 65 | | --------------- required by a bound in this function | ||
| 66 | | where | ||
| 67 | | F: TaskFn<Args, Fut = Fut>, | ||
| 68 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_align` | ||
| 69 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 70 | |||
| 71 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 72 | --> tests/ui/return_impl_send.rs:4:4 | ||
| 73 | | | ||
| 74 | 3 | #[embassy_executor::task] | ||
| 75 | | ------------------------- required by a bound introduced by this call | ||
| 76 | 4 | fn task() -> impl Send {} | ||
| 77 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 78 | | | ||
| 79 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 80 | note: required by a bound in `task_pool_new` | ||
| 81 | --> src/lib.rs | ||
| 82 | | | ||
| 83 | | pub const fn task_pool_new<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> TaskPool<Fut, POOL_SIZE> | ||
| 84 | | ------------- required by a bound in this function | ||
| 85 | | where | ||
| 86 | | F: TaskFn<Args, Fut = Fut>, | ||
| 87 | | ^^^^^^^^^ required by this bound in `task_pool_new` | ||
| 88 | |||
| 89 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 90 | --> tests/ui/return_impl_send.rs:3:1 | ||
| 91 | | | ||
| 92 | 3 | #[embassy_executor::task] | ||
| 93 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 94 | | | ||
| 95 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 96 | note: required by a bound in `task_pool_new` | ||
| 97 | --> src/lib.rs | ||
| 98 | | | ||
| 99 | | pub const fn task_pool_new<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> TaskPool<Fut, POOL_SIZE> | ||
| 100 | | ------------- required by a bound in this function | ||
| 101 | | where | ||
| 102 | | F: TaskFn<Args, Fut = Fut>, | ||
| 103 | | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `task_pool_new` | ||
| 104 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 105 | |||
| 106 | error[E0277]: task futures must resolve to `()` or `!` | ||
| 107 | --> tests/ui/return_impl_send.rs:4:4 | ||
| 108 | | | ||
| 109 | 3 | #[embassy_executor::task] | ||
| 110 | | ------------------------- required by a bound introduced by this call | ||
| 111 | 4 | fn task() -> impl Send {} | ||
| 112 | | ^^^^ the trait `TaskFn<_>` is not implemented for fn item `fn() -> impl Send {__task_task}` | ||
| 113 | | | ||
| 114 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | ||
| 115 | note: required by a bound in `__task_pool_get` | ||
| 116 | --> tests/ui/return_impl_send.rs:3:1 | ||
| 117 | | | ||
| 118 | 3 | #[embassy_executor::task] | ||
| 119 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__task_pool_get` | ||
| 120 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 121 | |||
| 122 | error[E0277]: `impl Send` is not a future | ||
| 123 | --> tests/ui/return_impl_send.rs:3:1 | ||
| 124 | | | ||
| 125 | 3 | #[embassy_executor::task] | ||
| 126 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Send` is not a future | ||
| 127 | | | ||
| 128 | = help: the trait `Future` is not implemented for `impl Send` | ||
| 129 | note: required by a bound in `TaskPool::<F, N>::_spawn_async_fn` | ||
| 130 | --> src/raw/mod.rs | ||
| 131 | | | ||
| 132 | | impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | ||
| 133 | | ^^^^^^ required by this bound in `TaskPool::<F, N>::_spawn_async_fn` | ||
| 134 | ... | ||
| 135 | | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> SpawnToken<impl Sized> | ||
| 136 | | --------------- required by a bound in this associated function | ||
| 137 | = 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 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | fn task() -> impl Send {} | ||
| 5 | |||
| 6 | 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 @@ | |||
| 1 | error[E0277]: `impl Send` is not a future | ||
| 2 | --> tests/ui/return_impl_send_nightly.rs:3:1 | ||
| 3 | | | ||
| 4 | 3 | #[embassy_executor::task] | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 6 | | | | ||
| 7 | | `impl Send` is not a future | ||
| 8 | | return type was inferred to be `impl Send` here | ||
| 9 | | | ||
| 10 | = help: the trait `Future` is not implemented for `impl Send` | ||
