@@ -278,7 +278,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
278278 self . tcx
279279 }
280280
281- fn fold_binder < T > ( & mut self , t : ty:: Binder < ' tcx , T > ) -> ty:: Binder < ' tcx , T >
281+ fn fold_binder < T > ( & mut self , t : ty:: Binder < ' tcx , T > ) -> Result < ty:: Binder < ' tcx , T > , Self :: Error >
282282 where
283283 T : TypeFoldable < ' tcx > ,
284284 {
@@ -288,13 +288,13 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
288288 t
289289 }
290290
291- fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
291+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , Self :: Error > {
292292 match * r {
293293 ty:: ReLateBound ( index, ..) => {
294294 if index >= self . binder_index {
295295 bug ! ( "escaping late-bound region during canonicalization" ) ;
296296 } else {
297- r
297+ Ok ( r )
298298 }
299299 }
300300
@@ -311,19 +311,19 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
311311 vid, r
312312 ) ;
313313 let r = self . tcx . reuse_or_mk_region ( r, ty:: ReVar ( resolved_vid) ) ;
314- self . canonicalize_region_mode . canonicalize_free_region ( self , r)
314+ Ok ( self . canonicalize_region_mode . canonicalize_free_region ( self , r) )
315315 }
316316
317317 ty:: ReStatic
318318 | ty:: ReEarlyBound ( ..)
319319 | ty:: ReFree ( _)
320320 | ty:: ReEmpty ( _)
321321 | ty:: RePlaceholder ( ..)
322- | ty:: ReErased => self . canonicalize_region_mode . canonicalize_free_region ( self , r) ,
322+ | ty:: ReErased => Ok ( self . canonicalize_region_mode . canonicalize_free_region ( self , r) ) ,
323323 }
324324 }
325325
326- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
326+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
327327 match * t. kind ( ) {
328328 ty:: Infer ( ty:: TyVar ( vid) ) => {
329329 debug ! ( "canonical: type var found with vid {:?}" , vid) ;
@@ -339,40 +339,40 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
339339 Err ( mut ui) => {
340340 // FIXME: perf problem described in #55921.
341341 ui = ty:: UniverseIndex :: ROOT ;
342- self . canonicalize_ty_var (
342+ Ok ( self . canonicalize_ty_var (
343343 CanonicalVarInfo {
344344 kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) ) ,
345345 } ,
346346 t,
347- )
347+ ) )
348348 }
349349 }
350350 }
351351
352- ty:: Infer ( ty:: IntVar ( _) ) => self . canonicalize_ty_var (
352+ ty:: Infer ( ty:: IntVar ( _) ) => Ok ( self . canonicalize_ty_var (
353353 CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) } ,
354354 t,
355- ) ,
355+ ) ) ,
356356
357- ty:: Infer ( ty:: FloatVar ( _) ) => self . canonicalize_ty_var (
357+ ty:: Infer ( ty:: FloatVar ( _) ) => Ok ( self . canonicalize_ty_var (
358358 CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) } ,
359359 t,
360- ) ,
360+ ) ) ,
361361
362362 ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
363363 bug ! ( "encountered a fresh type during canonicalization" )
364364 }
365365
366- ty:: Placeholder ( placeholder) => self . canonicalize_ty_var (
366+ ty:: Placeholder ( placeholder) => Ok ( self . canonicalize_ty_var (
367367 CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderTy ( placeholder) } ,
368368 t,
369- ) ,
369+ ) ) ,
370370
371371 ty:: Bound ( debruijn, _) => {
372372 if debruijn >= self . binder_index {
373373 bug ! ( "escaping bound type during canonicalization" )
374374 } else {
375- t
375+ Ok ( t )
376376 }
377377 }
378378
@@ -403,13 +403,16 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
403403 if t. flags ( ) . intersects ( self . needs_canonical_flags ) {
404404 t. super_fold_with ( self )
405405 } else {
406- t
406+ Ok ( t )
407407 }
408408 }
409409 }
410410 }
411411
412- fn fold_const ( & mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
412+ fn fold_const (
413+ & mut self ,
414+ ct : & ' tcx ty:: Const < ' tcx > ,
415+ ) -> Result < & ' tcx ty:: Const < ' tcx > , Self :: Error > {
413416 match ct. val {
414417 ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) => {
415418 debug ! ( "canonical: const var found with vid {:?}" , vid) ;
@@ -424,10 +427,10 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
424427 Err ( mut ui) => {
425428 // FIXME: perf problem described in #55921.
426429 ui = ty:: UniverseIndex :: ROOT ;
427- return self . canonicalize_const_var (
430+ return Ok ( self . canonicalize_const_var (
428431 CanonicalVarInfo { kind : CanonicalVarKind :: Const ( ui) } ,
429432 ct,
430- ) ;
433+ ) ) ;
431434 }
432435 }
433436 }
@@ -438,20 +441,20 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
438441 if debruijn >= self . binder_index {
439442 bug ! ( "escaping bound type during canonicalization" )
440443 } else {
441- return ct ;
444+ return Ok ( ct ) ;
442445 }
443446 }
444447 ty:: ConstKind :: Placeholder ( placeholder) => {
445- return self . canonicalize_const_var (
448+ return Ok ( self . canonicalize_const_var (
446449 CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderConst ( placeholder) } ,
447450 ct,
448- ) ;
451+ ) ) ;
449452 }
450453 _ => { }
451454 }
452455
453456 let flags = FlagComputation :: for_const ( ct) ;
454- if flags. intersects ( self . needs_canonical_flags ) { ct. super_fold_with ( self ) } else { ct }
457+ if flags. intersects ( self . needs_canonical_flags ) { ct. super_fold_with ( self ) } else { Ok ( ct ) }
455458 }
456459}
457460
@@ -500,7 +503,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
500503 indices : FxHashMap :: default ( ) ,
501504 binder_index : ty:: INNERMOST ,
502505 } ;
503- let out_value = value. fold_with ( & mut canonicalizer) ;
506+ let out_value = value. fold_with ( & mut canonicalizer) . into_ok ( ) ;
504507
505508 // Once we have canonicalized `out_value`, it should not
506509 // contain anything that ties it to this inference context
@@ -618,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
618621 let infcx = self . infcx ;
619622 let bound_to = infcx. shallow_resolve ( ty_var) ;
620623 if bound_to != ty_var {
621- self . fold_ty ( bound_to)
624+ self . fold_ty ( bound_to) . into_ok ( )
622625 } else {
623626 let var = self . canonical_var ( info, ty_var. into ( ) ) ;
624627 self . tcx ( ) . mk_ty ( ty:: Bound ( self . binder_index , var. into ( ) ) )
@@ -637,12 +640,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
637640 let infcx = self . infcx ;
638641 let bound_to = infcx. shallow_resolve ( const_var) ;
639642 if bound_to != const_var {
640- self . fold_const ( bound_to)
643+ self . fold_const ( bound_to) . into_ok ( )
641644 } else {
642645 let var = self . canonical_var ( info, const_var. into ( ) ) ;
643646 self . tcx ( ) . mk_const ( ty:: Const {
644647 val : ty:: ConstKind :: Bound ( self . binder_index , var) ,
645- ty : self . fold_ty ( const_var. ty ) ,
648+ ty : self . fold_ty ( const_var. ty ) . into_ok ( ) ,
646649 } )
647650 }
648651 }
0 commit comments