diff options
| author | Brezak <[email protected]> | 2025-07-22 20:56:46 +0200 |
|---|---|---|
| committer | Brezak <[email protected]> | 2025-07-23 19:19:02 +0200 |
| commit | a52965dc5d3d0c706310998d3eda8bc15cd45b02 (patch) | |
| tree | 64087a9a6391c6ded8c7ddfb06652152b1b0759e /embassy-executor-macros/src | |
| parent | a5984a8298491ea748693783275d95286a481394 (diff) | |
embassy-executor: unsafe tasks as unsafe
Diffstat (limited to 'embassy-executor-macros/src')
| -rw-r--r-- | embassy-executor-macros/src/macros/task.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 1c5e3571d..f01cc3b6c 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs | |||
| @@ -120,6 +120,18 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 120 | task_inner.vis = syn::Visibility::Inherited; | 120 | task_inner.vis = syn::Visibility::Inherited; |
| 121 | task_inner.sig.ident = task_inner_ident.clone(); | 121 | task_inner.sig.ident = task_inner_ident.clone(); |
| 122 | 122 | ||
| 123 | // Forcefully mark the inner task as safe. | ||
| 124 | // SAFETY: We only ever call task_inner in functions | ||
| 125 | // with the same safety preconditions as task_inner | ||
| 126 | task_inner.sig.unsafety = None; | ||
| 127 | let task_body = task_inner.body; | ||
| 128 | task_inner.body = quote! { | ||
| 129 | #[allow(unused_unsafe, reason = "Not all function bodies may require being in an unsafe block")] | ||
| 130 | unsafe { | ||
| 131 | #task_body | ||
| 132 | } | ||
| 133 | }; | ||
| 134 | |||
| 123 | // assemble the original input arguments, | 135 | // assemble the original input arguments, |
| 124 | // including any attributes that may have | 136 | // including any attributes that may have |
| 125 | // been applied previously | 137 | // been applied previously |
| @@ -186,6 +198,7 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 186 | // Copy the generics + where clause to avoid more spurious errors. | 198 | // Copy the generics + where clause to avoid more spurious errors. |
| 187 | let generics = &f.sig.generics; | 199 | let generics = &f.sig.generics; |
| 188 | let where_clause = &f.sig.generics.where_clause; | 200 | let where_clause = &f.sig.generics.where_clause; |
| 201 | let unsafety = &f.sig.unsafety; | ||
| 189 | 202 | ||
| 190 | let result = quote! { | 203 | let result = quote! { |
| 191 | // This is the user's task function, renamed. | 204 | // This is the user's task function, renamed. |
| @@ -196,7 +209,7 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 196 | #task_inner | 209 | #task_inner |
| 197 | 210 | ||
| 198 | #(#task_outer_attrs)* | 211 | #(#task_outer_attrs)* |
| 199 | #visibility fn #task_ident #generics (#fargs) -> #embassy_executor::SpawnToken<impl Sized> #where_clause{ | 212 | #visibility #unsafety fn #task_ident #generics (#fargs) -> #embassy_executor::SpawnToken<impl Sized> #where_clause{ |
| 200 | #task_outer_body | 213 | #task_outer_body |
| 201 | } | 214 | } |
| 202 | 215 | ||
