diff options
Diffstat (limited to 'embassy-executor/tests')
| -rw-r--r-- | embassy-executor/tests/test.rs | 11 | ||||
| -rw-r--r-- | embassy-executor/tests/ui.rs | 3 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr | 2 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/nonstatic_struct_elided.stderr | 14 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/task_safety_attribute.rs | 25 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/unsafe_op_in_unsafe_task.rs | 10 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr | 18 |
7 files changed, 81 insertions, 2 deletions
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index c1e7ec5d7..b84d3785a 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex}; | |||
| 7 | use std::task::Poll; | 7 | use std::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_executor::raw::Executor; | 9 | use embassy_executor::raw::Executor; |
| 10 | use embassy_executor::task; | 10 | use embassy_executor::{task, Spawner}; |
| 11 | 11 | ||
| 12 | #[export_name = "__pender"] | 12 | #[export_name = "__pender"] |
| 13 | fn __pender(context: *mut ()) { | 13 | fn __pender(context: *mut ()) { |
| @@ -317,3 +317,12 @@ fn executor_task_cfg_args() { | |||
| 317 | let (_, _, _) = (a, b, c); | 317 | let (_, _, _) = (a, b, c); |
| 318 | } | 318 | } |
| 319 | } | 319 | } |
| 320 | |||
| 321 | #[test] | ||
| 322 | fn recursive_task() { | ||
| 323 | #[embassy_executor::task(pool_size = 2)] | ||
| 324 | async fn task1() { | ||
| 325 | let spawner = unsafe { Spawner::for_current_executor().await }; | ||
| 326 | spawner.spawn(task1()); | ||
| 327 | } | ||
| 328 | } | ||
diff --git a/embassy-executor/tests/ui.rs b/embassy-executor/tests/ui.rs index 7757775ee..5486a0624 100644 --- a/embassy-executor/tests/ui.rs +++ b/embassy-executor/tests/ui.rs | |||
| @@ -32,4 +32,7 @@ fn ui() { | |||
| 32 | t.compile_fail("tests/ui/self.rs"); | 32 | t.compile_fail("tests/ui/self.rs"); |
| 33 | t.compile_fail("tests/ui/type_error.rs"); | 33 | t.compile_fail("tests/ui/type_error.rs"); |
| 34 | t.compile_fail("tests/ui/where_clause.rs"); | 34 | t.compile_fail("tests/ui/where_clause.rs"); |
| 35 | t.compile_fail("tests/ui/unsafe_op_in_unsafe_task.rs"); | ||
| 36 | |||
| 37 | t.pass("tests/ui/task_safety_attribute.rs"); | ||
| 35 | } | 38 | } |
diff --git a/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr index 73ceb989d..3c3c9503b 100644 --- a/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr +++ b/embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr | |||
| @@ -7,4 +7,4 @@ error[E0277]: task futures must resolve to `()` or `!` | |||
| 7 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` | 7 | = note: use `async fn` or change the return type to `impl Future<Output = ()>` |
| 8 | = help: the following other types implement trait `TaskReturnValue`: | 8 | = help: the following other types implement trait `TaskReturnValue`: |
| 9 | () | 9 | () |
| 10 | <fn() -> ! as _export::HasOutput>::Output | 10 | <fn() -> ! as HasOutput>::Output |
diff --git a/embassy-executor/tests/ui/nonstatic_struct_elided.stderr b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr index 099ef8b4e..0ee1bfe0c 100644 --- a/embassy-executor/tests/ui/nonstatic_struct_elided.stderr +++ b/embassy-executor/tests/ui/nonstatic_struct_elided.stderr | |||
| @@ -8,3 +8,17 @@ help: indicate the anonymous lifetime | |||
| 8 | | | 8 | | |
| 9 | 6 | async fn task(_x: Foo<'_>) {} | 9 | 6 | async fn task(_x: Foo<'_>) {} |
| 10 | | ++++ | 10 | | ++++ |
| 11 | |||
| 12 | error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds | ||
| 13 | --> tests/ui/nonstatic_struct_elided.rs:5:1 | ||
| 14 | | | ||
| 15 | 5 | #[embassy_executor::task] | ||
| 16 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type defined here | ||
| 17 | 6 | async fn task(_x: Foo) {} | ||
| 18 | | --- hidden type `impl Sized` captures the anonymous lifetime defined here | ||
| 19 | | | ||
| 20 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| 21 | help: add a `use<...>` bound to explicitly capture `'_` | ||
| 22 | | | ||
| 23 | 5 | #[embassy_executor::task] + use<'_> | ||
| 24 | | +++++++++ | ||
diff --git a/embassy-executor/tests/ui/task_safety_attribute.rs b/embassy-executor/tests/ui/task_safety_attribute.rs new file mode 100644 index 000000000..ab5a2f99f --- /dev/null +++ b/embassy-executor/tests/ui/task_safety_attribute.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | #![deny(unused_unsafe)] | ||
| 3 | |||
| 4 | use std::mem; | ||
| 5 | |||
| 6 | #[embassy_executor::task] | ||
| 7 | async fn safe() {} | ||
| 8 | |||
| 9 | #[embassy_executor::task] | ||
| 10 | async unsafe fn not_safe() {} | ||
| 11 | |||
| 12 | #[export_name = "__pender"] | ||
| 13 | fn pender(_: *mut ()) { | ||
| 14 | // The test doesn't link if we don't include this. | ||
| 15 | // We never call this anyway. | ||
| 16 | } | ||
| 17 | |||
| 18 | fn main() { | ||
| 19 | let _forget_me = safe(); | ||
| 20 | // SAFETY: not_safe has not safety preconditions | ||
| 21 | let _forget_me2 = unsafe { not_safe() }; | ||
| 22 | |||
| 23 | mem::forget(_forget_me); | ||
| 24 | mem::forget(_forget_me2); | ||
| 25 | } | ||
diff --git a/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.rs b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.rs new file mode 100644 index 000000000..ee7924838 --- /dev/null +++ b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.rs | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | #![deny(unsafe_op_in_unsafe_fn)] | ||
| 3 | |||
| 4 | #[embassy_executor::task] | ||
| 5 | async unsafe fn task() { | ||
| 6 | let x = 5; | ||
| 7 | (&x as *const i32).read(); | ||
| 8 | } | ||
| 9 | |||
| 10 | fn main() {} | ||
diff --git a/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr new file mode 100644 index 000000000..d987a4b95 --- /dev/null +++ b/embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | error[E0133]: call to unsafe function `std::ptr::const_ptr::<impl *const T>::read` is unsafe and requires unsafe block | ||
| 2 | --> tests/ui/unsafe_op_in_unsafe_task.rs:7:5 | ||
| 3 | | | ||
| 4 | 7 | (&x as *const i32).read(); | ||
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | ||
| 6 | | | ||
| 7 | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html> | ||
| 8 | = note: consult the function's documentation for information on how to avoid undefined behavior | ||
| 9 | note: an unsafe function restricts its caller, but its body is safe by default | ||
| 10 | --> tests/ui/unsafe_op_in_unsafe_task.rs:5:1 | ||
| 11 | | | ||
| 12 | 5 | async unsafe fn task() { | ||
| 13 | | ^^^^^^^^^^^^^^^^^^^^^^ | ||
| 14 | note: the lint level is defined here | ||
| 15 | --> tests/ui/unsafe_op_in_unsafe_task.rs:2:9 | ||
| 16 | | | ||
| 17 | 2 | #![deny(unsafe_op_in_unsafe_fn)] | ||
| 18 | | ^^^^^^^^^^^^^^^^^^^^^^ | ||
