diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index c37ad212c..396ce18f2 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs @@ -33,12 +33,10 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { ctxt.error_spanned_by(arg, "task functions must not have receiver arguments"); @@ -46,8 +44,6 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result match t.pat.as_mut() { syn::Pat::Ident(id) => { arg_names.push(id.ident.clone()); - arg_types.push(t.ty.clone()); - arg_indexes.push(syn::Index::from(i)); id.mutability = None; } _ => { @@ -64,8 +60,6 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result Result #embassy_path::executor::SpawnToken { + use ::core::future::Future; use #embassy_path::executor::SpawnToken; use #embassy_path::executor::raw::TaskStorage; - type Fut = impl ::core::future::Future + 'static; + type Fut = impl Future + 'static; #[allow(clippy::declare_interior_mutable_const)] const NEW_TS: TaskStorage = TaskStorage::new(); static POOL: [TaskStorage; #pool_size] = [NEW_TS; #pool_size]; - pub(super) fn task(args: super::#args_ident) -> SpawnToken { - unsafe { TaskStorage::spawn_pool(&POOL, move || super::#task_inner_ident(#(args.#arg_indexes),*)) } + // Opaque type laundering, to obscure its origin! + // Workaround for "opaque type's hidden type cannot be another opaque type from the same scope" + // https://github.com/rust-lang/rust/issues/96406 + fn launder_tait(token: SpawnToken) -> SpawnToken { + token } - } - #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken { - #mod_ident::task((#(#arg_names,)*)) + launder_tait(unsafe { TaskStorage::spawn_pool(&POOL, move || #task_inner_ident(#(#arg_names,)*)) }) } };