diff options
| author | jrmoulton <[email protected]> | 2025-06-10 15:47:54 -0600 |
|---|---|---|
| committer | jrmoulton <[email protected]> | 2025-06-10 15:48:36 -0600 |
| commit | cfad9798ff99d4de0571a512d156b5fe1ef1d427 (patch) | |
| tree | fc3bf670f82d139de19466cddad1e909db7f3d2e /embassy-executor/tests | |
| parent | fc342915e6155dec7bafa3e135da7f37a9a07f5c (diff) | |
| parent | 6186d111a5c150946ee5b7e9e68d987a38c1a463 (diff) | |
merge new embassy changes
Diffstat (limited to 'embassy-executor/tests')
38 files changed, 423 insertions, 0 deletions
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 348cc7dc4..78c49c071 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -40,6 +40,7 @@ fn setup() -> (&'static Executor, Trace) { | |||
| 40 | let trace = Trace::new(); | 40 | let trace = Trace::new(); |
| 41 | let context = Box::leak(Box::new(trace.clone())) as *mut _ as *mut (); | 41 | let context = Box::leak(Box::new(trace.clone())) as *mut _ as *mut (); |
| 42 | let executor = &*Box::leak(Box::new(Executor::new(context))); | 42 | let executor = &*Box::leak(Box::new(Executor::new(context))); |
| 43 | |||
| 43 | (executor, trace) | 44 | (executor, trace) |
| 44 | } | 45 | } |
| 45 | 46 | ||
| @@ -137,6 +138,139 @@ fn executor_task_self_wake_twice() { | |||
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | #[test] | 140 | #[test] |
| 141 | fn waking_after_completion_does_not_poll() { | ||
| 142 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 143 | |||
| 144 | #[task] | ||
| 145 | async fn task1(trace: Trace, waker: &'static AtomicWaker) { | ||
| 146 | poll_fn(|cx| { | ||
| 147 | trace.push("poll task1"); | ||
| 148 | waker.register(cx.waker()); | ||
| 149 | Poll::Ready(()) | ||
| 150 | }) | ||
| 151 | .await | ||
| 152 | } | ||
| 153 | |||
| 154 | let waker = Box::leak(Box::new(AtomicWaker::new())); | ||
| 155 | |||
| 156 | let (executor, trace) = setup(); | ||
| 157 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | ||
| 158 | |||
| 159 | unsafe { executor.poll() }; | ||
| 160 | waker.wake(); | ||
| 161 | unsafe { executor.poll() }; | ||
| 162 | |||
| 163 | // Exited task may be waken but is not polled | ||
| 164 | waker.wake(); | ||
| 165 | waker.wake(); | ||
| 166 | unsafe { executor.poll() }; // Clears running status | ||
| 167 | |||
| 168 | // Can respawn waken-but-dead task | ||
| 169 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | ||
| 170 | |||
| 171 | unsafe { executor.poll() }; | ||
| 172 | |||
| 173 | assert_eq!( | ||
| 174 | trace.get(), | ||
| 175 | &[ | ||
| 176 | "pend", // spawning a task pends the executor | ||
| 177 | "poll task1", // | ||
| 178 | "pend", // manual wake, gets cleared by poll | ||
| 179 | "pend", // manual wake, single pend for two wakes | ||
| 180 | "pend", // respawning a task pends the executor | ||
| 181 | "poll task1", // | ||
| 182 | ] | ||
| 183 | ) | ||
| 184 | } | ||
| 185 | |||
| 186 | #[test] | ||
| 187 | fn waking_with_old_waker_after_respawn() { | ||
| 188 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 189 | |||
| 190 | async fn yield_now(trace: Trace) { | ||
| 191 | let mut yielded = false; | ||
| 192 | poll_fn(|cx| { | ||
| 193 | if yielded { | ||
| 194 | Poll::Ready(()) | ||
| 195 | } else { | ||
| 196 | trace.push("yield_now"); | ||
| 197 | yielded = true; | ||
| 198 | cx.waker().wake_by_ref(); | ||
| 199 | Poll::Pending | ||
| 200 | } | ||
| 201 | }) | ||
| 202 | .await | ||
| 203 | } | ||
| 204 | |||
| 205 | #[task] | ||
| 206 | async fn task1(trace: Trace, waker: &'static AtomicWaker) { | ||
| 207 | yield_now(trace.clone()).await; | ||
| 208 | poll_fn(|cx| { | ||
| 209 | trace.push("poll task1"); | ||
| 210 | waker.register(cx.waker()); | ||
| 211 | Poll::Ready(()) | ||
| 212 | }) | ||
| 213 | .await; | ||
| 214 | } | ||
| 215 | |||
| 216 | let waker = Box::leak(Box::new(AtomicWaker::new())); | ||
| 217 | |||
| 218 | let (executor, trace) = setup(); | ||
| 219 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | ||
| 220 | |||
| 221 | unsafe { executor.poll() }; | ||
| 222 | unsafe { executor.poll() }; // progress to registering the waker | ||
| 223 | waker.wake(); | ||
| 224 | unsafe { executor.poll() }; | ||
| 225 | // Task has exited | ||
| 226 | |||
| 227 | assert_eq!( | ||
| 228 | trace.get(), | ||
| 229 | &[ | ||
| 230 | "pend", // spawning a task pends the executor | ||
| 231 | "yield_now", // | ||
| 232 | "pend", // yield_now wakes the task | ||
| 233 | "poll task1", // | ||
| 234 | "pend", // task self-wakes | ||
| 235 | ] | ||
| 236 | ); | ||
| 237 | |||
| 238 | // Can respawn task on another executor | ||
| 239 | let (other_executor, other_trace) = setup(); | ||
| 240 | other_executor | ||
| 241 | .spawner() | ||
| 242 | .spawn(task1(other_trace.clone(), waker)) | ||
| 243 | .unwrap(); | ||
| 244 | |||
| 245 | unsafe { other_executor.poll() }; // just run to the yield_now | ||
| 246 | waker.wake(); // trigger old waker registration | ||
| 247 | unsafe { executor.poll() }; | ||
| 248 | unsafe { other_executor.poll() }; | ||
| 249 | |||
| 250 | // First executor's trace has not changed | ||
| 251 | assert_eq!( | ||
| 252 | trace.get(), | ||
| 253 | &[ | ||
| 254 | "pend", // spawning a task pends the executor | ||
| 255 | "yield_now", // | ||
| 256 | "pend", // yield_now wakes the task | ||
| 257 | "poll task1", // | ||
| 258 | "pend", // task self-wakes | ||
| 259 | ] | ||
| 260 | ); | ||
| 261 | |||
| 262 | assert_eq!( | ||
| 263 | other_trace.get(), | ||
| 264 | &[ | ||
| 265 | "pend", // spawning a task pends the executor | ||
| 266 | "yield_now", // | ||
| 267 | "pend", // manual wake, gets cleared by poll | ||
| 268 | "poll task1", // | ||
| 269 | ] | ||
| 270 | ); | ||
| 271 | } | ||
| 272 | |||
| 273 | #[test] | ||
| 140 | fn executor_task_cfg_args() { | 274 | fn executor_task_cfg_args() { |
| 141 | // simulate cfg'ing away argument c | 275 | // simulate cfg'ing away argument c |
| 142 | #[task] | 276 | #[task] |
diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs new file mode 100644 index 000000000..278a4b903 --- /dev/null +++ b/embassy-executor/tests/ui.rs | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #[cfg(not(miri))] | ||
| 2 | #[test] | ||
| 3 | fn ui() { | ||
| 4 | let t = trybuild::TestCases::new(); | ||
| 5 | t.compile_fail("tests/ui/abi.rs"); | ||
| 6 | t.compile_fail("tests/ui/bad_return.rs"); | ||
| 7 | t.compile_fail("tests/ui/generics.rs"); | ||
| 8 | t.compile_fail("tests/ui/impl_trait_nested.rs"); | ||
| 9 | t.compile_fail("tests/ui/impl_trait.rs"); | ||
| 10 | t.compile_fail("tests/ui/impl_trait_static.rs"); | ||
| 11 | t.compile_fail("tests/ui/nonstatic_ref_anon_nested.rs"); | ||
| 12 | t.compile_fail("tests/ui/nonstatic_ref_anon.rs"); | ||
| 13 | t.compile_fail("tests/ui/nonstatic_ref_elided.rs"); | ||
| 14 | t.compile_fail("tests/ui/nonstatic_ref_generic.rs"); | ||
| 15 | t.compile_fail("tests/ui/nonstatic_struct_anon.rs"); | ||
| 16 | #[cfg(not(feature = "nightly"))] // we can't catch this case with the macro, so the output changes on nightly. | ||
| 17 | t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); | ||
| 18 | t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); | ||
| 19 | t.compile_fail("tests/ui/not_async.rs"); | ||
| 20 | t.compile_fail("tests/ui/self_ref.rs"); | ||
| 21 | t.compile_fail("tests/ui/self.rs"); | ||
| 22 | t.compile_fail("tests/ui/type_error.rs"); | ||
| 23 | t.compile_fail("tests/ui/where_clause.rs"); | ||
| 24 | } | ||
diff --git a/embassy-executor/tests/ui/abi.rs b/embassy-executor/tests/ui/abi.rs new file mode 100644 index 000000000..fd52f7e41 --- /dev/null +++ b/embassy-executor/tests/ui/abi.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async extern "C" fn task() {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/abi.stderr b/embassy-executor/tests/ui/abi.stderr new file mode 100644 index 000000000..e264e371a --- /dev/null +++ b/embassy-executor/tests/ui/abi.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: task functions must not have an ABI qualifier | ||
| 2 | --> tests/ui/abi.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | async extern "C" fn task() {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/bad_return.rs b/embassy-executor/tests/ui/bad_return.rs new file mode 100644 index 000000000..f09a5205b --- /dev/null +++ b/embassy-executor/tests/ui/bad_return.rs | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task() -> u32 { | ||
| 7 | 5 | ||
| 8 | } | ||
| 9 | |||
| 10 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/bad_return.stderr b/embassy-executor/tests/ui/bad_return.stderr new file mode 100644 index 000000000..e9d94dff8 --- /dev/null +++ b/embassy-executor/tests/ui/bad_return.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: task functions must either not return a value, return `()` or return `!` | ||
| 2 | --> tests/ui/bad_return.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | async fn task() -> u32 { | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/generics.rs b/embassy-executor/tests/ui/generics.rs new file mode 100644 index 000000000..b83123bb1 --- /dev/null +++ b/embassy-executor/tests/ui/generics.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task<T: Sized>(_t: T) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/generics.stderr b/embassy-executor/tests/ui/generics.stderr new file mode 100644 index 000000000..197719a7b --- /dev/null +++ b/embassy-executor/tests/ui/generics.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: task functions must not be generic | ||
| 2 | --> tests/ui/generics.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | async fn task<T: Sized>(_t: T) {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/impl_trait.rs b/embassy-executor/tests/ui/impl_trait.rs new file mode 100644 index 000000000..a21402aa0 --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo(_x: impl Sized) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/impl_trait.stderr b/embassy-executor/tests/ui/impl_trait.stderr new file mode 100644 index 000000000..099b1828f --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
| 2 | --> tests/ui/impl_trait.rs:4:18 | ||
| 3 | | | ||
| 4 | 4 | async fn foo(_x: impl Sized) {} | ||
| 5 | | ^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/impl_trait_nested.rs b/embassy-executor/tests/ui/impl_trait_nested.rs new file mode 100644 index 000000000..07442b8fa --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait_nested.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<T>(T); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn foo(_x: Foo<impl Sized + 'static>) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/impl_trait_nested.stderr b/embassy-executor/tests/ui/impl_trait_nested.stderr new file mode 100644 index 000000000..39592f958 --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait_nested.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
| 2 | --> tests/ui/impl_trait_nested.rs:6:22 | ||
| 3 | | | ||
| 4 | 6 | async fn foo(_x: Foo<impl Sized + 'static>) {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/impl_trait_static.rs b/embassy-executor/tests/ui/impl_trait_static.rs new file mode 100644 index 000000000..272470f98 --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait_static.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo(_x: impl Sized + 'static) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/impl_trait_static.stderr b/embassy-executor/tests/ui/impl_trait_static.stderr new file mode 100644 index 000000000..0032a20c9 --- /dev/null +++ b/embassy-executor/tests/ui/impl_trait_static.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
| 2 | --> tests/ui/impl_trait_static.rs:4:18 | ||
| 3 | | | ||
| 4 | 4 | async fn foo(_x: impl Sized + 'static) {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_anon.rs b/embassy-executor/tests/ui/nonstatic_ref_anon.rs new file mode 100644 index 000000000..417c360a1 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_anon.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo(_x: &'_ u32) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_anon.stderr b/embassy-executor/tests/ui/nonstatic_ref_anon.stderr new file mode 100644 index 000000000..0544de843 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_anon.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 2 | --> tests/ui/nonstatic_ref_anon.rs:4:19 | ||
| 3 | | | ||
| 4 | 4 | async fn foo(_x: &'_ u32) {} | ||
| 5 | | ^^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_anon_nested.rs b/embassy-executor/tests/ui/nonstatic_ref_anon_nested.rs new file mode 100644 index 000000000..175ebccc1 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_anon_nested.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo(_x: &'static &'_ u32) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_anon_nested.stderr b/embassy-executor/tests/ui/nonstatic_ref_anon_nested.stderr new file mode 100644 index 000000000..79f262e6b --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_anon_nested.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 2 | --> tests/ui/nonstatic_ref_anon_nested.rs:4:28 | ||
| 3 | | | ||
| 4 | 4 | async fn foo(_x: &'static &'_ u32) {} | ||
| 5 | | ^^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_elided.rs b/embassy-executor/tests/ui/nonstatic_ref_elided.rs new file mode 100644 index 000000000..cf49ad709 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_elided.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo(_x: &u32) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_elided.stderr b/embassy-executor/tests/ui/nonstatic_ref_elided.stderr new file mode 100644 index 000000000..7e2b9eb7c --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_elided.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 2 | --> tests/ui/nonstatic_ref_elided.rs:4:18 | ||
| 3 | | | ||
| 4 | 4 | async fn foo(_x: &u32) {} | ||
| 5 | | ^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_generic.rs b/embassy-executor/tests/ui/nonstatic_ref_generic.rs new file mode 100644 index 000000000..3f8a26cf8 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_generic.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn foo<'a>(_x: &'a u32) {} | ||
| 5 | |||
| 6 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_ref_generic.stderr b/embassy-executor/tests/ui/nonstatic_ref_generic.stderr new file mode 100644 index 000000000..af8491ad7 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_ref_generic.stderr | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | error: task functions must not be generic | ||
| 2 | --> tests/ui/nonstatic_ref_generic.rs:4:1 | ||
| 3 | | | ||
| 4 | 4 | async fn foo<'a>(_x: &'a u32) {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 6 | |||
| 7 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 8 | --> tests/ui/nonstatic_ref_generic.rs:4:23 | ||
| 9 | | | ||
| 10 | 4 | async fn foo<'a>(_x: &'a u32) {} | ||
| 11 | | ^^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_anon.rs b/embassy-executor/tests/ui/nonstatic_struct_anon.rs new file mode 100644 index 000000000..ba95d1459 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_anon.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task(_x: Foo<'_>) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_anon.stderr b/embassy-executor/tests/ui/nonstatic_struct_anon.stderr new file mode 100644 index 000000000..5df2a6e06 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_anon.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 2 | --> tests/ui/nonstatic_struct_anon.rs:6:23 | ||
| 3 | | | ||
| 4 | 6 | async fn task(_x: Foo<'_>) {} | ||
| 5 | | ^^ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_elided.rs b/embassy-executor/tests/ui/nonstatic_struct_elided.rs new file mode 100644 index 000000000..4cfe2966a --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_elided.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task(_x: Foo) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_elided.stderr b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr new file mode 100644 index 000000000..099ef8b4e --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | error[E0726]: implicit elided lifetime not allowed here | ||
| 2 | --> tests/ui/nonstatic_struct_elided.rs:6:19 | ||
| 3 | | | ||
| 4 | 6 | async fn task(_x: Foo) {} | ||
| 5 | | ^^^ expected lifetime parameter | ||
| 6 | | | ||
| 7 | help: indicate the anonymous lifetime | ||
| 8 | | | ||
| 9 | 6 | async fn task(_x: Foo<'_>) {} | ||
| 10 | | ++++ | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_generic.rs b/embassy-executor/tests/ui/nonstatic_struct_generic.rs new file mode 100644 index 000000000..ec3d908f6 --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_generic.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task<'a>(_x: Foo<'a>) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/nonstatic_struct_generic.stderr b/embassy-executor/tests/ui/nonstatic_struct_generic.stderr new file mode 100644 index 000000000..61d5231bc --- /dev/null +++ b/embassy-executor/tests/ui/nonstatic_struct_generic.stderr | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | error: task functions must not be generic | ||
| 2 | --> tests/ui/nonstatic_struct_generic.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | async fn task<'a>(_x: Foo<'a>) {} | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 6 | |||
| 7 | error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
| 8 | --> tests/ui/nonstatic_struct_generic.rs:6:27 | ||
| 9 | | | ||
| 10 | 6 | async fn task<'a>(_x: Foo<'a>) {} | ||
| 11 | | ^^ | ||
diff --git a/embassy-executor/tests/ui/not_async.rs b/embassy-executor/tests/ui/not_async.rs new file mode 100644 index 000000000..f3f7e9bd2 --- /dev/null +++ b/embassy-executor/tests/ui/not_async.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | fn task() {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/not_async.stderr b/embassy-executor/tests/ui/not_async.stderr new file mode 100644 index 000000000..27f040d9c --- /dev/null +++ b/embassy-executor/tests/ui/not_async.stderr | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | error: task functions must be async | ||
| 2 | --> tests/ui/not_async.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | fn task() {} | ||
| 5 | | ^^^^^^^^^ | ||
diff --git a/embassy-executor/tests/ui/self.rs b/embassy-executor/tests/ui/self.rs new file mode 100644 index 000000000..f83a962d1 --- /dev/null +++ b/embassy-executor/tests/ui/self.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task(self) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/self.stderr b/embassy-executor/tests/ui/self.stderr new file mode 100644 index 000000000..aaf031573 --- /dev/null +++ b/embassy-executor/tests/ui/self.stderr | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | error: task functions must not have `self` arguments | ||
| 2 | --> tests/ui/self.rs:6:15 | ||
| 3 | | | ||
| 4 | 6 | async fn task(self) {} | ||
| 5 | | ^^^^ | ||
| 6 | |||
| 7 | error: `self` parameter is only allowed in associated functions | ||
| 8 | --> tests/ui/self.rs:6:15 | ||
| 9 | | | ||
| 10 | 6 | async fn task(self) {} | ||
| 11 | | ^^^^ not semantically valid as function parameter | ||
| 12 | | | ||
| 13 | = note: associated functions are those in `impl` or `trait` definitions | ||
diff --git a/embassy-executor/tests/ui/self_ref.rs b/embassy-executor/tests/ui/self_ref.rs new file mode 100644 index 000000000..5e49bba5e --- /dev/null +++ b/embassy-executor/tests/ui/self_ref.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task(&mut self) {} | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/self_ref.stderr b/embassy-executor/tests/ui/self_ref.stderr new file mode 100644 index 000000000..dd2052977 --- /dev/null +++ b/embassy-executor/tests/ui/self_ref.stderr | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | error: task functions must not have `self` arguments | ||
| 2 | --> tests/ui/self_ref.rs:6:15 | ||
| 3 | | | ||
| 4 | 6 | async fn task(&mut self) {} | ||
| 5 | | ^^^^^^^^^ | ||
| 6 | |||
| 7 | error: `self` parameter is only allowed in associated functions | ||
| 8 | --> tests/ui/self_ref.rs:6:15 | ||
| 9 | | | ||
| 10 | 6 | async fn task(&mut self) {} | ||
| 11 | | ^^^^^^^^^ not semantically valid as function parameter | ||
| 12 | | | ||
| 13 | = note: associated functions are those in `impl` or `trait` definitions | ||
diff --git a/embassy-executor/tests/ui/type_error.rs b/embassy-executor/tests/ui/type_error.rs new file mode 100644 index 000000000..1734bc6c4 --- /dev/null +++ b/embassy-executor/tests/ui/type_error.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | #[embassy_executor::task] | ||
| 4 | async fn task() { | ||
| 5 | 5 | ||
| 6 | } | ||
| 7 | |||
| 8 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/type_error.stderr b/embassy-executor/tests/ui/type_error.stderr new file mode 100644 index 000000000..bce315811 --- /dev/null +++ b/embassy-executor/tests/ui/type_error.stderr | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | error[E0308]: mismatched types | ||
| 2 | --> tests/ui/type_error.rs:5:5 | ||
| 3 | | | ||
| 4 | 4 | async fn task() { | ||
| 5 | | - help: try adding a return type: `-> i32` | ||
| 6 | 5 | 5 | ||
| 7 | | ^ expected `()`, found integer | ||
diff --git a/embassy-executor/tests/ui/where_clause.rs b/embassy-executor/tests/ui/where_clause.rs new file mode 100644 index 000000000..848d78149 --- /dev/null +++ b/embassy-executor/tests/ui/where_clause.rs | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | |||
| 3 | struct Foo<'a>(&'a ()); | ||
| 4 | |||
| 5 | #[embassy_executor::task] | ||
| 6 | async fn task() | ||
| 7 | where | ||
| 8 | (): Sized, | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/where_clause.stderr b/embassy-executor/tests/ui/where_clause.stderr new file mode 100644 index 000000000..eba45af40 --- /dev/null +++ b/embassy-executor/tests/ui/where_clause.stderr | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | error: task functions must not have `where` clauses | ||
| 2 | --> tests/ui/where_clause.rs:6:1 | ||
| 3 | | | ||
| 4 | 6 | / async fn task() | ||
| 5 | 7 | | where | ||
| 6 | 8 | | (): Sized, | ||
| 7 | | |______________^ | ||
