diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 05:18:48 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 05:18:48 +0800 |
| commit | d28dbd820af73aa9dc93d2df6c89d6f8c840e907 (patch) | |
| tree | 689a92ef7589fe0b395110410cd20b101412838c | |
| parent | cd9cad77542e1909f9600f8a2e2754cc4cc4507a (diff) | |
fix: generate async-compatible empty do_chain fallback
When a program declares no chains, the synthesized `do_chain` now
respects the `async` feature by emitting a boxed future signature
with a `Box::pin(async { panic! })` body, matching the trait
requirement and fixing E0053 in async builds.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | mingling_macros/src/func/program_final_gen.rs | 22 |
2 files changed, 20 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e216f6b..ed8d388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,7 +58,7 @@ None #### Fixes: -None +1. **[`macros:gen_program`]** Fixed the empty `do_chain` fallback generated by `program_final_gen` to respect the `async` feature. When a program has no chains registered, the synthesized `do_chain` previously always emitted the synchronous signature `fn do_chain(...) -> ChainProcess<Self::Enum>`, which fails to compile under the `async` feature with E0053 (method signature does not match the `ProgramCollect` trait, which requires a `Pin<Box<dyn Future<Output = ChainProcess> + Send>>` return in async mode). The generator now checks the compile-time `ASYNC_ENABLED` flag for the empty-chain case, mirroring the non-empty branch: when async is enabled it emits the boxed-future signature with a `Box::pin(async { panic!(...) })` body, and otherwise emits the synchronous signature. This fixes programs that declare zero chains (relying solely on entry/fallback behavior) when built with the `async` feature. #### Optimizations: diff --git a/mingling_macros/src/func/program_final_gen.rs b/mingling_macros/src/func/program_final_gen.rs index 8123eaf..ceee66d 100644 --- a/mingling_macros/src/func/program_final_gen.rs +++ b/mingling_macros/src/func/program_final_gen.rs @@ -273,9 +273,25 @@ pub(crate) fn program_final_gen_impl(_input: TokenStream) -> TokenStream { .collect(); let do_chain_fn = if chain_tokens.is_empty() { - quote! { - fn do_chain(_any: ::mingling::AnyOutput<Self::Enum>) -> ::mingling::ChainProcess<Self::Enum> { - ::core::panic!("No chain found for type id") + // An empty chain list is still valid, but the synthesized `do_chain` + // must match the trait signature for the enabled mode. The sync + // branch used unconditionally breaks the `async` feature (E0053), + // so dispatch on `ASYNC_ENABLED` here as well. + if ASYNC_ENABLED { + quote! { + fn do_chain( + _any: ::mingling::AnyOutput<Self::Enum>, + ) -> ::std::pin::Pin<::std::boxed::Box<dyn ::std::future::Future<Output = ::mingling::ChainProcess<Self::Enum>> + ::std::marker::Send>> { + ::std::boxed::Box::pin(async { + ::core::panic!("No chain found for type id") + }) + } + } + } else { + quote! { + fn do_chain(_any: ::mingling::AnyOutput<Self::Enum>) -> ::mingling::ChainProcess<Self::Enum> { + ::core::panic!("No chain found for type id") + } } } } else if ASYNC_ENABLED { |
