File tree 2 files changed +41
-45
lines changed
2 files changed +41
-45
lines changed Original file line number Diff line number Diff line change @@ -888,48 +888,3 @@ impl dyn Error + Send + Sync {
888
888
} )
889
889
}
890
890
}
891
-
892
- #[ cfg( test) ]
893
- mod tests {
894
- use super :: Error ;
895
- use core:: fmt;
896
-
897
- #[ derive( Debug , PartialEq ) ]
898
- struct A ;
899
- #[ derive( Debug , PartialEq ) ]
900
- struct B ;
901
-
902
- impl fmt:: Display for A {
903
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
904
- write ! ( f, "A" )
905
- }
906
- }
907
- impl fmt:: Display for B {
908
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
909
- write ! ( f, "B" )
910
- }
911
- }
912
-
913
- impl Error for A {
914
- fn description ( & self ) -> & str { "A-desc" }
915
- }
916
- impl Error for B {
917
- fn description ( & self ) -> & str { "A-desc" }
918
- }
919
-
920
- #[ test]
921
- fn downcasting ( ) {
922
- let mut a = A ;
923
- let a = & mut a as & mut ( dyn Error + ' static ) ;
924
- assert_eq ! ( a. downcast_ref:: <A >( ) , Some ( & A ) ) ;
925
- assert_eq ! ( a. downcast_ref:: <B >( ) , None ) ;
926
- assert_eq ! ( a. downcast_mut:: <A >( ) , Some ( & mut A ) ) ;
927
- assert_eq ! ( a. downcast_mut:: <B >( ) , None ) ;
928
-
929
- let a: Box < dyn Error > = Box :: new ( A ) ;
930
- match a. downcast :: < B > ( ) {
931
- Ok ( ..) => panic ! ( "expected error" ) ,
932
- Err ( e) => assert_eq ! ( * e. downcast:: <A >( ) . unwrap( ) , A ) ,
933
- }
934
- }
935
- }
Original file line number Diff line number Diff line change
1
+ use std:: error:: Error ;
2
+ use std:: fmt;
3
+
4
+ #[ derive( Debug , PartialEq ) ]
5
+ struct A ;
6
+ #[ derive( Debug , PartialEq ) ]
7
+ struct B ;
8
+
9
+ impl fmt:: Display for A {
10
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
11
+ write ! ( f, "A" )
12
+ }
13
+ }
14
+ impl fmt:: Display for B {
15
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
16
+ write ! ( f, "B" )
17
+ }
18
+ }
19
+
20
+ impl Error for A {
21
+ fn description ( & self ) -> & str { "A-desc" }
22
+ }
23
+ impl Error for B {
24
+ fn description ( & self ) -> & str { "A-desc" }
25
+ }
26
+
27
+ #[ test]
28
+ fn downcasting ( ) {
29
+ let mut a = A ;
30
+ let a = & mut a as & mut ( dyn Error + ' static ) ;
31
+ assert_eq ! ( a. downcast_ref:: <A >( ) , Some ( & A ) ) ;
32
+ assert_eq ! ( a. downcast_ref:: <B >( ) , None ) ;
33
+ assert_eq ! ( a. downcast_mut:: <A >( ) , Some ( & mut A ) ) ;
34
+ assert_eq ! ( a. downcast_mut:: <B >( ) , None ) ;
35
+
36
+ let a: Box < dyn Error > = Box :: new ( A ) ;
37
+ match a. downcast :: < B > ( ) {
38
+ Ok ( ..) => panic ! ( "expected error" ) ,
39
+ Err ( e) => assert_eq ! ( * e. downcast:: <A >( ) . unwrap( ) , A ) ,
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments