diff options
| author | Matthew Tran <[email protected]> | 2025-05-28 22:00:25 -0500 |
|---|---|---|
| committer | Matthew Tran <[email protected]> | 2025-05-28 23:37:17 -0500 |
| commit | a4d4f62a1e0e808ec3dd93e282f517a2f8ad9fa5 (patch) | |
| tree | 30529d5f171a70131885c840b6de040da6c5082a /embassy-executor/tests | |
| parent | 4766cc6f9756b54bb2e25be5ba5276538ea4917b (diff) | |
Allow `-> impl Future<Output = ()>` in #[task]
Diffstat (limited to 'embassy-executor/tests')
| -rw-r--r-- | embassy-executor/tests/test.rs | 24 | ||||
| -rw-r--r-- | embassy-executor/tests/ui.rs | 4 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_trait.rs | 9 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_trait.stderr | 120 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_trait_nightly.rs | 9 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_trait_nightly.stderr | 9 |
6 files changed, 174 insertions, 1 deletions
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 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] |
| 2 | 2 | ||
| 3 | use std::boxed::Box; | 3 | use std::boxed::Box; |
| 4 | use std::future::poll_fn; | 4 | use std::future::{poll_fn, Future}; |
| 5 | use std::sync::{Arc, Mutex}; | 5 | use std::sync::{Arc, Mutex}; |
| 6 | use std::task::Poll; | 6 | use std::task::Poll; |
| 7 | 7 | ||
| @@ -74,6 +74,28 @@ fn executor_task() { | |||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | #[test] | 76 | #[test] |
| 77 | fn executor_task_rpit() { | ||
| 78 | #[task] | ||
| 79 | fn task1(trace: Trace) -> impl Future<Output = ()> { | ||
| 80 | async move { trace.push("poll task1") } | ||
| 81 | } | ||
| 82 | |||
| 83 | let (executor, trace) = setup(); | ||
| 84 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | ||
| 85 | |||
| 86 | unsafe { executor.poll() }; | ||
| 87 | unsafe { executor.poll() }; | ||
| 88 | |||
| 89 | assert_eq!( | ||
| 90 | trace.get(), | ||
| 91 | &[ | ||
| 92 | "pend", // spawning a task pends the executor | ||
| 93 | "poll task1", // poll only once. | ||
| 94 | ] | ||
| 95 | ) | ||
| 96 | } | ||
| 97 | |||
| 98 | #[test] | ||
| 77 | fn executor_task_self_wake() { | 99 | fn executor_task_self_wake() { |
| 78 | #[task] | 100 | #[task] |
| 79 | async fn task1(trace: Trace) { | 101 | async fn task1(trace: Trace) { |
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() { | |||
| 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 | // #[cfg(not(feature = "nightly"))] // output differs on stable and nightly | ||
| 21 | // t.compile_fail("tests/ui/bad_return_impl_trait.rs"); | ||
| 22 | #[cfg(feature = "nightly")] | ||
| 23 | t.compile_fail("tests/ui/bad_return_impl_trait_nightly.rs"); | ||
| 20 | t.compile_fail("tests/ui/self_ref.rs"); | 24 | t.compile_fail("tests/ui/self_ref.rs"); |
| 21 | t.compile_fail("tests/ui/self.rs"); | 25 | t.compile_fail("tests/ui/self.rs"); |
| 22 | t.compile_fail("tests/ui/type_error.rs"); | 26 | 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 @@ | |||
| 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_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 @@ | |||
| 1 | error[E0277]: task function futures must resolve to `()` | ||
| 2 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 20 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 37 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 55 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 72 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 90 | --> tests/ui/bad_return_impl_trait.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 function futures must resolve to `()` | ||
| 107 | --> tests/ui/bad_return_impl_trait.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_trait.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_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 @@ | |||
| 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_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 @@ | |||
| 1 | error[E0277]: the trait bound `u32: TaskReturnValue` is not satisfied | ||
| 2 | --> tests/ui/bad_return_impl_trait_nightly.rs:4:1 | ||
| 3 | | | ||
| 4 | 4 | #[embassy_executor::task] | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TaskReturnValue` is not implemented for `u32` | ||
| 6 | | | ||
| 7 | = help: the following other types implement trait `TaskReturnValue`: | ||
| 8 | () | ||
| 9 | <fn() -> ! as _export::HasOutput>::Output | ||
