46
46
//! ```
47
47
use crate :: { visit:: TypeVisitable , Interner } ;
48
48
49
+ #[ cfg( feature = "nightly" ) ]
50
+ type Never = !;
51
+
52
+ #[ cfg( not( feature = "nightly" ) ) ]
53
+ type Never = std:: convert:: Infallible ;
54
+
49
55
/// This trait is implemented for every type that can be folded,
50
56
/// providing the skeleton of the traversal.
51
57
///
@@ -74,7 +80,10 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
74
80
/// folders. Do not override this method, to ensure coherence with
75
81
/// `try_fold_with`.
76
82
fn fold_with < F : TypeFolder < I > > ( self , folder : & mut F ) -> Self {
77
- self . try_fold_with ( folder) . into_ok ( )
83
+ match self . try_fold_with ( folder) {
84
+ Ok ( t) => t,
85
+ Err ( e) => match e { } ,
86
+ }
78
87
}
79
88
}
80
89
@@ -95,7 +104,10 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
95
104
/// infallible folders. Do not override this method, to ensure coherence
96
105
/// with `try_super_fold_with`.
97
106
fn super_fold_with < F : TypeFolder < I > > ( self , folder : & mut F ) -> Self {
98
- self . try_super_fold_with ( folder) . into_ok ( )
107
+ match self . try_super_fold_with ( folder) {
108
+ Ok ( t) => t,
109
+ Err ( e) => match e { } ,
110
+ }
99
111
}
100
112
}
101
113
@@ -108,7 +120,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
108
120
/// A blanket implementation of [`FallibleTypeFolder`] will defer to
109
121
/// the infallible methods of this trait to ensure that the two APIs
110
122
/// are coherent.
111
- pub trait TypeFolder < I : Interner > : FallibleTypeFolder < I , Error = ! > {
123
+ pub trait TypeFolder < I : Interner > : FallibleTypeFolder < I , Error = Never > {
112
124
fn interner ( & self ) -> I ;
113
125
114
126
fn fold_binder < T > ( & mut self , t : I :: Binder < T > ) -> I :: Binder < T >
@@ -203,39 +215,39 @@ impl<I: Interner, F> FallibleTypeFolder<I> for F
203
215
where
204
216
F : TypeFolder < I > ,
205
217
{
206
- type Error = ! ;
218
+ type Error = Never ;
207
219
208
220
fn interner ( & self ) -> I {
209
221
TypeFolder :: interner ( self )
210
222
}
211
223
212
- fn try_fold_binder < T > ( & mut self , t : I :: Binder < T > ) -> Result < I :: Binder < T > , ! >
224
+ fn try_fold_binder < T > ( & mut self , t : I :: Binder < T > ) -> Result < I :: Binder < T > , Never >
213
225
where
214
226
T : TypeFoldable < I > ,
215
227
I :: Binder < T > : TypeSuperFoldable < I > ,
216
228
{
217
229
Ok ( self . fold_binder ( t) )
218
230
}
219
231
220
- fn try_fold_ty ( & mut self , t : I :: Ty ) -> Result < I :: Ty , ! >
232
+ fn try_fold_ty ( & mut self , t : I :: Ty ) -> Result < I :: Ty , Never >
221
233
where
222
234
I :: Ty : TypeSuperFoldable < I > ,
223
235
{
224
236
Ok ( self . fold_ty ( t) )
225
237
}
226
238
227
- fn try_fold_region ( & mut self , r : I :: Region ) -> Result < I :: Region , ! > {
239
+ fn try_fold_region ( & mut self , r : I :: Region ) -> Result < I :: Region , Never > {
228
240
Ok ( self . fold_region ( r) )
229
241
}
230
242
231
- fn try_fold_const ( & mut self , c : I :: Const ) -> Result < I :: Const , ! >
243
+ fn try_fold_const ( & mut self , c : I :: Const ) -> Result < I :: Const , Never >
232
244
where
233
245
I :: Const : TypeSuperFoldable < I > ,
234
246
{
235
247
Ok ( self . fold_const ( c) )
236
248
}
237
249
238
- fn try_fold_predicate ( & mut self , p : I :: Predicate ) -> Result < I :: Predicate , ! >
250
+ fn try_fold_predicate ( & mut self , p : I :: Predicate ) -> Result < I :: Predicate , Never >
239
251
where
240
252
I :: Predicate : TypeSuperFoldable < I > ,
241
253
{
0 commit comments