diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-12 02:34:39 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-12 02:34:39 +0800 |
| commit | 4e163438f9d9af83c1492826acf742337ec147c9 (patch) | |
| tree | 94055401a7c958e0fe5e6f8e4143cccdf86e7e06 | |
| parent | d5a039e9d882f8f50b3cc9cdc10bc7bd84a5fa4d (diff) | |
fix: suppress future_not_send lint and tighten Send bounds
Add `#[allow(clippy::future_not_send)]` to chain invocation methods and
clarify Send requirements for `exec` bounds.
| -rw-r--r-- | mingling_core/src/asset/core_invokes.rs | 9 | ||||
| -rw-r--r-- | mingling_core/src/program/collection.rs | 2 | ||||
| -rw-r--r-- | mingling_core/src/program/exec.rs | 4 | ||||
| -rw-r--r-- | mingling_core/src/program/hook.rs | 10 | ||||
| -rw-r--r-- | mingling_core/src/program/once_exec.rs | 6 | ||||
| -rw-r--r-- | mingling_core/src/program/repl_exec.rs | 10 |
6 files changed, 33 insertions, 8 deletions
diff --git a/mingling_core/src/asset/core_invokes.rs b/mingling_core/src/asset/core_invokes.rs index 07e5092..705568b 100644 --- a/mingling_core/src/asset/core_invokes.rs +++ b/mingling_core/src/asset/core_invokes.rs @@ -135,6 +135,9 @@ where /// /// It will not execute any program hooks, because this type is used for **bypassing** or **reusing**, not for flow control. #[might_be_async::func] + #[allow(clippy::future_not_send)] + // The generated future is only awaited within the single-threaded chain + // execution, so it does not need to be `Send`. pub fn invoke_once<C>(&self, value: T) -> ChainProcess<C> where C: ProgramCollect<Enum = C> + 'static, @@ -165,6 +168,9 @@ where /// /// It will not execute any program hooks, because this type is used for **bypassing** or **reusing**, not for flow control. #[might_be_async::func] + // The generated future is only awaited within the single-threaded chain + // execution, so it does not need to be `Send`. + #[allow(clippy::future_not_send)] pub fn invoke_to_last<C>(&self, value: T) -> ChainProcess<C> where C: ProgramCollect<Enum = C> + 'static, @@ -207,6 +213,9 @@ where /// /// It will not execute any program hooks, because this type is used for **bypassing** or **reusing**, not for flow control. #[might_be_async::func] + #[allow(clippy::future_not_send)] + // The generated future is only awaited within the single-threaded chain + // execution, so it does not need to be `Send`. pub fn invoke_to_result<C>(&self, value: T) -> RenderResult where C: ProgramCollect<Enum = C> + 'static, diff --git a/mingling_core/src/program/collection.rs b/mingling_core/src/program/collection.rs index 66ec9f1..6ec4a27 100644 --- a/mingling_core/src/program/collection.rs +++ b/mingling_core/src/program/collection.rs @@ -82,7 +82,7 @@ pub trait ProgramCollect { None } - /// Find a matching chain to continue execution based on the input [AnyOutput](./struct.AnyOutput.html), returning a new [AnyOutput](./struct.AnyOutput.html) + /// Find a matching chain to continue execution based on the input [`AnyOutput`](./struct.AnyOutput.html), returning a new [`AnyOutput`](./struct.AnyOutput.html) #[cfg(feature = "async")] fn do_chain( any: AnyOutput<Self::Enum>, diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index df42249..5948cfe 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -12,7 +12,7 @@ pub mod error; #[might_be_async::func] pub fn exec<C>(program: &'static Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> where - C: ProgramCollect<Enum = C>, + C: ProgramCollect<Enum = C> + Send + Sync, { might_be_async::invoke!(exec_with_args(program, &program.args)) } @@ -23,7 +23,7 @@ pub fn exec_with_args<C>( args: &[String], ) -> Result<RenderResult, ProgramInternalExecuteError> where - C: ProgramCollect<Enum = C>, + C: ProgramCollect<Enum = C> + Send + Sync, { // Exit code let mut exit_code: i32 = 0; diff --git a/mingling_core/src/program/hook.rs b/mingling_core/src/program/hook.rs index 0bcc051..6f468b3 100644 --- a/mingling_core/src/program/hook.rs +++ b/mingling_core/src/program/hook.rs @@ -737,6 +737,16 @@ mod tests { unreachable!() } + #[cfg(feature = "async")] + fn do_chain( + _any: crate::AnyOutput<Self>, + ) -> std::pin::Pin< + Box<dyn std::future::Future<Output = crate::ChainProcess<Self>> + Send + 'static>, + > { + Box::pin(async { unreachable!() }) + } + + #[cfg(not(feature = "async"))] fn do_chain(_any: crate::AnyOutput<Self>) -> crate::ChainProcess<Self> { unreachable!() } diff --git a/mingling_core/src/program/once_exec.rs b/mingling_core/src/program/once_exec.rs index 18e06ef..fc48e6d 100644 --- a/mingling_core/src/program/once_exec.rs +++ b/mingling_core/src/program/once_exec.rs @@ -59,7 +59,7 @@ where #[cfg(feature = "async")] { return self - .exec_wrapper(|p| async { crate::exec::exec(p).await.map_err(|e| e.into()) }) + .exec_wrapper(|p| async { crate::exec::exec(p).await.map_err(Into::into) }) .await; } } @@ -129,14 +129,14 @@ where pub(crate) async fn exec_wrapper<F, Fut>(self, f: F) -> Fut::Output where C: 'static + Send + Sync, - F: FnOnce(&'static Program<C>) -> Fut + Send + Sync, + F: FnOnce(&'static Self) -> Fut + Send + Sync, Fut: Future + Send, { THIS_PROGRAM.set(Box::new(self)); let program = THIS_PROGRAM .get_raw() .unwrap() - .downcast_ref::<Program<C>>() + .downcast_ref::<Self>() .unwrap(); f(program).await diff --git a/mingling_core/src/program/repl_exec.rs b/mingling_core/src/program/repl_exec.rs index ea36c75..fe29d16 100644 --- a/mingling_core/src/program/repl_exec.rs +++ b/mingling_core/src/program/repl_exec.rs @@ -35,6 +35,7 @@ where self.exec_wrapper(async |p| -> () { repl_loop(p).await; }) + .await else self.exec_wrapper(|p| -> () { repl_loop(p); } ) @@ -65,8 +66,13 @@ where result: &r, }); } + #[allow(unused_variables)] Err(ProgramInternalExecuteError::REPLPanic(panic)) => { - p.run_hook_repl_on_panic(&crate::hook::HookREPLOnPanicInfo { panic: &panic }); + might_be_async::select![ + {} else { + p.run_hook_repl_on_panic(&crate::hook::HookREPLOnPanicInfo { panic: &panic }); + } + ]; } _ => {} } @@ -128,5 +134,5 @@ async fn exec_once<C>( where C: ProgramCollect<Enum = C> + Send + Sync + 'static, { - super::exec::exec_with_args(p, &args).await + super::exec::exec_with_args(p, args).await } |
