4646//! ```
4747use crate :: { visit:: TypeVisitable , Interner } ;
4848
49+ #[ cfg( feature = "nightly" ) ]
50+ type Never = !;
51+
52+ #[ cfg( not( feature = "nightly" ) ) ]
53+ type Never = std:: convert:: Infallible ;
54+
4955/// This trait is implemented for every type that can be folded,
5056/// providing the skeleton of the traversal.
5157///
@@ -74,7 +80,10 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
7480 /// folders. Do not override this method, to ensure coherence with
7581 /// `try_fold_with`.
7682 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+ }
7887 }
7988}
8089
@@ -95,7 +104,10 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
95104 /// infallible folders. Do not override this method, to ensure coherence
96105 /// with `try_super_fold_with`.
97106 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+ }
99111 }
100112}
101113
@@ -108,7 +120,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
108120/// A blanket implementation of [`FallibleTypeFolder`] will defer to
109121/// the infallible methods of this trait to ensure that the two APIs
110122/// are coherent.
111- pub trait TypeFolder < I : Interner > : FallibleTypeFolder < I , Error = ! > {
123+ pub trait TypeFolder < I : Interner > : FallibleTypeFolder < I , Error = Never > {
112124 fn interner ( & self ) -> I ;
113125
114126 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
203215where
204216 F : TypeFolder < I > ,
205217{
206- type Error = ! ;
218+ type Error = Never ;
207219
208220 fn interner ( & self ) -> I {
209221 TypeFolder :: interner ( self )
210222 }
211223
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 >
213225 where
214226 T : TypeFoldable < I > ,
215227 I :: Binder < T > : TypeSuperFoldable < I > ,
216228 {
217229 Ok ( self . fold_binder ( t) )
218230 }
219231
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 >
221233 where
222234 I :: Ty : TypeSuperFoldable < I > ,
223235 {
224236 Ok ( self . fold_ty ( t) )
225237 }
226238
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 > {
228240 Ok ( self . fold_region ( r) )
229241 }
230242
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 >
232244 where
233245 I :: Const : TypeSuperFoldable < I > ,
234246 {
235247 Ok ( self . fold_const ( c) )
236248 }
237249
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 >
239251 where
240252 I :: Predicate : TypeSuperFoldable < I > ,
241253 {
0 commit comments