@@ -213,6 +213,7 @@ impl DefinitelySame for Error {
213
213
impl DefinitelySame for error_chain:: State {
214
214
fn definitely_same ( & self , other : & Self ) -> bool {
215
215
// We ignore backtraces
216
+ // We have to remove the Send bounds, which current Rust makes a bit annoying
216
217
self . next_error . definitely_same ( & other. next_error )
217
218
}
218
219
}
@@ -413,3 +414,54 @@ where
413
414
self . with_instance ( |i| std:: fmt:: Debug :: fmt ( & i, f) )
414
415
}
415
416
}
417
+
418
+ #[ cfg( test) ]
419
+ mod tests {
420
+ use super :: * ;
421
+ use error_chain:: { ChainedError , State } ;
422
+ use std:: error:: Error as StdError ;
423
+
424
+ #[ test]
425
+ fn test_def_same_option ( ) {
426
+ let a = Some ( Box :: from ( NewError :: msg ( "A" ) ) ) ;
427
+ let b = Some ( Box :: from ( NewError :: msg ( "A" ) ) ) ;
428
+
429
+ assert ! ( a. definitely_same( & b) ) ;
430
+ assert ! ( b. definitely_same( & a) ) ;
431
+
432
+ let b = Some ( Box :: from ( NewError :: msg ( "B" ) ) ) ;
433
+ assert ! ( !a. definitely_same( & b) ) ;
434
+
435
+ let b = None ;
436
+ let c = None ;
437
+ assert ! ( !a. definitely_same( & b) ) ;
438
+ assert ! ( b. definitely_same( & c) ) ;
439
+ }
440
+
441
+ #[ test]
442
+ fn test_def_same_err ( ) {
443
+ let a = Error :: new ( ErrorKind :: Msg ( String :: from ( "A" ) ) , State :: default ( ) ) ;
444
+ let b = Error :: new ( ErrorKind :: Msg ( String :: from ( "A" ) ) , State :: default ( ) ) ;
445
+
446
+ // Different backtraces but should be same
447
+ assert ! ( a. definitely_same( & b) ) ;
448
+
449
+ let b = Error :: new ( ErrorKind :: BadLength ( 0 , 0 ) , State :: default ( ) ) ;
450
+ assert ! ( !a. definitely_same( & b) ) ;
451
+
452
+ let a = Error :: new ( ErrorKind :: NewStyle ( NewError :: msg ( "A" ) ) , State :: default ( ) ) ;
453
+ assert ! ( !a. definitely_same( & b) ) ;
454
+
455
+ let b = Error :: new ( ErrorKind :: NewStyle ( NewError :: msg ( "A" ) ) , State :: default ( ) ) ;
456
+ assert ! ( a. definitely_same( & b) ) ;
457
+ }
458
+
459
+ #[ test]
460
+ fn test_def_same_box_err ( ) {
461
+ let a: Box < dyn StdError + Send > = Box :: from ( NewError :: msg ( "A" ) ) ;
462
+ let b: Box < dyn StdError + Send > = Box :: from ( NewError :: msg ( "B" ) ) ;
463
+
464
+ assert ! ( a. definitely_same( & a) ) ;
465
+ assert ! ( !a. definitely_same( & b) ) ;
466
+ }
467
+ }
0 commit comments