aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/CHANGELOG.md1
-rw-r--r--embassy-executor/src/lib.rs8
-rw-r--r--embassy-executor/tests/test.rs11
-rw-r--r--embassy-executor/tests/ui.rs3
-rw-r--r--embassy-executor/tests/ui/bad_return_impl_future_nightly.stderr2
-rw-r--r--embassy-executor/tests/ui/nonstatic_struct_elided.stderr14
-rw-r--r--embassy-executor/tests/ui/task_safety_attribute.rs25
-rw-r--r--embassy-executor/tests/ui/unsafe_op_in_unsafe_task.rs10
-rw-r--r--embassy-executor/tests/ui/unsafe_op_in_unsafe_task.stderr18
9 files changed, 86 insertions, 6 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md
index 914863a83..7404961f3 100644
--- a/embassy-executor/CHANGELOG.md
+++ b/embassy-executor/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21- Added support for `-> impl Future<Output = ()>` in `#[task]` 21- Added support for `-> impl Future<Output = ()>` in `#[task]`
22- Fixed `Send` unsoundness with `-> impl Future` tasks 22- Fixed `Send` unsoundness with `-> impl Future` tasks
23- Marked `Spawner::for_current_executor` as `unsafe` 23- Marked `Spawner::for_current_executor` as `unsafe`
24- `#[task]` now properly marks the generated function as unsafe if the task is marked unsafe
24 25
25## 0.7.0 - 2025-01-02 26## 0.7.0 - 2025-01-02
26 27
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index e174a0594..0747db032 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -216,7 +216,7 @@ pub mod _export {
216 ); 216 );
217 217
218 #[allow(dead_code)] 218 #[allow(dead_code)]
219 trait HasOutput { 219 pub trait HasOutput {
220 type Output; 220 type Output;
221 } 221 }
222 222
@@ -225,7 +225,7 @@ pub mod _export {
225 } 225 }
226 226
227 #[allow(dead_code)] 227 #[allow(dead_code)]
228 type Never = <fn() -> ! as HasOutput>::Output; 228 pub type Never = <fn() -> ! as HasOutput>::Output;
229} 229}
230 230
231/// Implementation details for embassy macros. 231/// Implementation details for embassy macros.
@@ -242,7 +242,7 @@ pub mod _export {
242 impl TaskReturnValue for Never {} 242 impl TaskReturnValue for Never {}
243 243
244 #[allow(dead_code)] 244 #[allow(dead_code)]
245 trait HasOutput { 245 pub trait HasOutput {
246 type Output; 246 type Output;
247 } 247 }
248 248
@@ -251,5 +251,5 @@ pub mod _export {
251 } 251 }
252 252
253 #[allow(dead_code)] 253 #[allow(dead_code)]
254 type Never = <fn() -> ! as HasOutput>::Output; 254 pub type Never = <fn() -> ! as HasOutput>::Output;
255} 255}
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};
7use std::task::Poll; 7use std::task::Poll;
8 8
9use embassy_executor::raw::Executor; 9use embassy_executor::raw::Executor;
10use embassy_executor::task; 10use embassy_executor::{task, Spawner};
11 11
12#[export_name = "__pender"] 12#[export_name = "__pender"]
13fn __pender(context: *mut ()) { 13fn __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]
322fn 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 |
96 | async fn task(_x: Foo<'_>) {} 96 | async fn task(_x: Foo<'_>) {}
10 | ++++ 10 | ++++
11
12error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
13 --> tests/ui/nonstatic_struct_elided.rs:5:1
14 |
155 | #[embassy_executor::task]
16 | ^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type defined here
176 | 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)
21help: add a `use<...>` bound to explicitly capture `'_`
22 |
235 | #[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
4use std::mem;
5
6#[embassy_executor::task]
7async fn safe() {}
8
9#[embassy_executor::task]
10async unsafe fn not_safe() {}
11
12#[export_name = "__pender"]
13fn pender(_: *mut ()) {
14 // The test doesn't link if we don't include this.
15 // We never call this anyway.
16}
17
18fn 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]
5async unsafe fn task() {
6 let x = 5;
7 (&x as *const i32).read();
8}
9
10fn 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 @@
1error[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 |
47 | (&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
9note: 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 |
125 | async unsafe fn task() {
13 | ^^^^^^^^^^^^^^^^^^^^^^
14note: the lint level is defined here
15 --> tests/ui/unsafe_op_in_unsafe_task.rs:2:9
16 |
172 | #![deny(unsafe_op_in_unsafe_fn)]
18 | ^^^^^^^^^^^^^^^^^^^^^^