File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,59 @@ use syntax_pos::Span;
65
65
// variant argument) that does not require visiting, as in
66
66
// `is_cleanup` above.
67
67
68
+ /// `std::ops::Try` with an impl for `()`.
69
+ pub trait TryHarder {
70
+ type Ok ;
71
+ type Error ;
72
+
73
+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > ;
74
+ fn from_error ( v : Self :: Error ) -> Self ;
75
+ fn from_ok ( v : Self :: Ok ) -> Self ;
76
+ }
77
+
78
+ impl TryHarder for ( ) {
79
+ type Ok = ( ) ;
80
+ type Error = !;
81
+
82
+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > {
83
+ Ok ( ( ) )
84
+ }
85
+
86
+ fn from_error ( _: Self :: Error ) -> Self {
87
+ unimplemented ! ( )
88
+ }
89
+
90
+ fn from_ok ( v : Self :: Ok ) -> Self {
91
+ v
92
+ }
93
+ }
94
+
95
+ impl < T , E > TryHarder for Result < T , E > {
96
+ type Ok = T ;
97
+ type Error = E ;
98
+
99
+ fn into_result ( self ) -> Self {
100
+ self
101
+ }
102
+
103
+ fn from_error ( e : E ) -> Self {
104
+ Err ( e)
105
+ }
106
+
107
+ fn from_ok ( v : T ) -> Self {
108
+ Ok ( v)
109
+ }
110
+ }
111
+
112
+ macro_rules! yrt { // try backwards
113
+ ( $expr: expr) => {
114
+ match $expr. into_result( ) {
115
+ Ok ( v) => R :: from_ok( v) ,
116
+ Err ( e) => return R :: from_error( e) ,
117
+ }
118
+ }
119
+ }
120
+
68
121
macro_rules! make_mir_visitor {
69
122
( $visitor_trait_name: ident, $( $mutability: ident) ?) => {
70
123
pub trait $visitor_trait_name<' tcx> {
You can’t perform that action at this time.
0 commit comments