@@ -9,6 +9,12 @@ use std::sync::Arc;
9
9
10
10
use crate :: private:: Sealed ;
11
11
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
+
12
18
/// Error type returned by `mlua` methods.
13
19
#[ derive( Debug , Clone ) ]
14
20
#[ non_exhaustive]
@@ -191,7 +197,7 @@ pub enum Error {
191
197
/// Returning `Err(ExternalError(...))` from a Rust callback will raise the error as a Lua
192
198
/// error. The Rust code that originally invoked the Lua code then receives a `CallbackError`,
193
199
/// from which the original error (and a stack traceback) can be recovered.
194
- ExternalError ( Arc < dyn StdError + Send + Sync > ) ,
200
+ ExternalError ( Arc < DynStdError > ) ,
195
201
/// An error with additional context.
196
202
WithContext {
197
203
/// A string containing additional context.
@@ -345,7 +351,7 @@ impl Error {
345
351
346
352
/// Wraps an external error object.
347
353
#[ 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 {
349
355
Error :: ExternalError ( err. into ( ) . into ( ) )
350
356
}
351
357
@@ -406,7 +412,7 @@ pub trait ExternalError {
406
412
fn into_lua_err ( self ) -> Error ;
407
413
}
408
414
409
- impl < E : Into < Box < dyn StdError + Send + Sync > > > ExternalError for E {
415
+ impl < E : Into < Box < DynStdError > > > ExternalError for E {
410
416
fn into_lua_err ( self ) -> Error {
411
417
Error :: external ( self )
412
418
}
@@ -552,3 +558,13 @@ impl<'a> Iterator for Chain<'a> {
552
558
}
553
559
}
554
560
}
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