@@ -9,6 +9,12 @@ use std::sync::Arc;
99
1010use crate :: private:: Sealed ;
1111
12+ #[ cfg( feature = "error-send" ) ]
13+ type DynStdError = dyn StdError + Send + Sync ;
14+
15+ #[ cfg( not( feature = "error-send" ) ) ]
16+ type DynStdError = dyn StdError ;
17+
1218/// Error type returned by `mlua` methods.
1319#[ derive( Debug , Clone ) ]
1420#[ non_exhaustive]
@@ -191,7 +197,7 @@ pub enum Error {
191197 /// Returning `Err(ExternalError(...))` from a Rust callback will raise the error as a Lua
192198 /// error. The Rust code that originally invoked the Lua code then receives a `CallbackError`,
193199 /// from which the original error (and a stack traceback) can be recovered.
194- ExternalError ( Arc < dyn StdError + Send + Sync > ) ,
200+ ExternalError ( Arc < DynStdError > ) ,
195201 /// An error with additional context.
196202 WithContext {
197203 /// A string containing additional context.
@@ -345,7 +351,7 @@ impl Error {
345351
346352 /// Wraps an external error object.
347353 #[ inline]
348- pub fn external < T : Into < Box < dyn StdError + Send + Sync > > > ( err : T ) -> Self {
354+ pub fn external < T : Into < Box < DynStdError > > > ( err : T ) -> Self {
349355 Error :: ExternalError ( err. into ( ) . into ( ) )
350356 }
351357
@@ -406,7 +412,7 @@ pub trait ExternalError {
406412 fn into_lua_err ( self ) -> Error ;
407413}
408414
409- impl < E : Into < Box < dyn StdError + Send + Sync > > > ExternalError for E {
415+ impl < E : Into < Box < DynStdError > > > ExternalError for E {
410416 fn into_lua_err ( self ) -> Error {
411417 Error :: external ( self )
412418 }
@@ -552,3 +558,13 @@ impl<'a> Iterator for Chain<'a> {
552558 }
553559 }
554560}
561+
562+ #[ cfg( test) ]
563+ mod assertions {
564+ use super :: * ;
565+
566+ #[ cfg( not( feature = "error-send" ) ) ]
567+ static_assertions:: assert_not_impl_any!( Error : Send , Sync ) ;
568+ #[ cfg( feature = "send" ) ]
569+ static_assertions:: assert_impl_all!( Error : Send , Sync ) ;
570+ }
0 commit comments