@@ -278,7 +278,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
278
278
self . tcx
279
279
}
280
280
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 >
282
282
where
283
283
T : TypeFoldable < ' tcx > ,
284
284
{
@@ -288,13 +288,13 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
288
288
t
289
289
}
290
290
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 > {
292
292
match * r {
293
293
ty:: ReLateBound ( index, ..) => {
294
294
if index >= self . binder_index {
295
295
bug ! ( "escaping late-bound region during canonicalization" ) ;
296
296
} else {
297
- r
297
+ Ok ( r )
298
298
}
299
299
}
300
300
@@ -311,19 +311,19 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
311
311
vid, r
312
312
) ;
313
313
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) )
315
315
}
316
316
317
317
ty:: ReStatic
318
318
| ty:: ReEarlyBound ( ..)
319
319
| ty:: ReFree ( _)
320
320
| ty:: ReEmpty ( _)
321
321
| 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) ) ,
323
323
}
324
324
}
325
325
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 > {
327
327
match * t. kind ( ) {
328
328
ty:: Infer ( ty:: TyVar ( vid) ) => {
329
329
debug ! ( "canonical: type var found with vid {:?}" , vid) ;
@@ -339,40 +339,40 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
339
339
Err ( mut ui) => {
340
340
// FIXME: perf problem described in #55921.
341
341
ui = ty:: UniverseIndex :: ROOT ;
342
- self . canonicalize_ty_var (
342
+ Ok ( self . canonicalize_ty_var (
343
343
CanonicalVarInfo {
344
344
kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) ) ,
345
345
} ,
346
346
t,
347
- )
347
+ ) )
348
348
}
349
349
}
350
350
}
351
351
352
- ty:: Infer ( ty:: IntVar ( _) ) => self . canonicalize_ty_var (
352
+ ty:: Infer ( ty:: IntVar ( _) ) => Ok ( self . canonicalize_ty_var (
353
353
CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) } ,
354
354
t,
355
- ) ,
355
+ ) ) ,
356
356
357
- ty:: Infer ( ty:: FloatVar ( _) ) => self . canonicalize_ty_var (
357
+ ty:: Infer ( ty:: FloatVar ( _) ) => Ok ( self . canonicalize_ty_var (
358
358
CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) } ,
359
359
t,
360
- ) ,
360
+ ) ) ,
361
361
362
362
ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
363
363
bug ! ( "encountered a fresh type during canonicalization" )
364
364
}
365
365
366
- ty:: Placeholder ( placeholder) => self . canonicalize_ty_var (
366
+ ty:: Placeholder ( placeholder) => Ok ( self . canonicalize_ty_var (
367
367
CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderTy ( placeholder) } ,
368
368
t,
369
- ) ,
369
+ ) ) ,
370
370
371
371
ty:: Bound ( debruijn, _) => {
372
372
if debruijn >= self . binder_index {
373
373
bug ! ( "escaping bound type during canonicalization" )
374
374
} else {
375
- t
375
+ Ok ( t )
376
376
}
377
377
}
378
378
@@ -403,13 +403,16 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
403
403
if t. flags ( ) . intersects ( self . needs_canonical_flags ) {
404
404
t. super_fold_with ( self )
405
405
} else {
406
- t
406
+ Ok ( t )
407
407
}
408
408
}
409
409
}
410
410
}
411
411
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 > {
413
416
match ct. val {
414
417
ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) => {
415
418
debug ! ( "canonical: const var found with vid {:?}" , vid) ;
@@ -424,10 +427,10 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
424
427
Err ( mut ui) => {
425
428
// FIXME: perf problem described in #55921.
426
429
ui = ty:: UniverseIndex :: ROOT ;
427
- return self . canonicalize_const_var (
430
+ return Ok ( self . canonicalize_const_var (
428
431
CanonicalVarInfo { kind : CanonicalVarKind :: Const ( ui) } ,
429
432
ct,
430
- ) ;
433
+ ) ) ;
431
434
}
432
435
}
433
436
}
@@ -438,20 +441,20 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
438
441
if debruijn >= self . binder_index {
439
442
bug ! ( "escaping bound type during canonicalization" )
440
443
} else {
441
- return ct ;
444
+ return Ok ( ct ) ;
442
445
}
443
446
}
444
447
ty:: ConstKind :: Placeholder ( placeholder) => {
445
- return self . canonicalize_const_var (
448
+ return Ok ( self . canonicalize_const_var (
446
449
CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderConst ( placeholder) } ,
447
450
ct,
448
- ) ;
451
+ ) ) ;
449
452
}
450
453
_ => { }
451
454
}
452
455
453
456
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 ) }
455
458
}
456
459
}
457
460
@@ -500,7 +503,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
500
503
indices : FxHashMap :: default ( ) ,
501
504
binder_index : ty:: INNERMOST ,
502
505
} ;
503
- let out_value = value. fold_with ( & mut canonicalizer) ;
506
+ let out_value = value. fold_with ( & mut canonicalizer) . into_ok ( ) ;
504
507
505
508
// Once we have canonicalized `out_value`, it should not
506
509
// contain anything that ties it to this inference context
@@ -618,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
618
621
let infcx = self . infcx ;
619
622
let bound_to = infcx. shallow_resolve ( ty_var) ;
620
623
if bound_to != ty_var {
621
- self . fold_ty ( bound_to)
624
+ self . fold_ty ( bound_to) . into_ok ( )
622
625
} else {
623
626
let var = self . canonical_var ( info, ty_var. into ( ) ) ;
624
627
self . tcx ( ) . mk_ty ( ty:: Bound ( self . binder_index , var. into ( ) ) )
@@ -637,12 +640,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
637
640
let infcx = self . infcx ;
638
641
let bound_to = infcx. shallow_resolve ( const_var) ;
639
642
if bound_to != const_var {
640
- self . fold_const ( bound_to)
643
+ self . fold_const ( bound_to) . into_ok ( )
641
644
} else {
642
645
let var = self . canonical_var ( info, const_var. into ( ) ) ;
643
646
self . tcx ( ) . mk_const ( ty:: Const {
644
647
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 ( ) ,
646
649
} )
647
650
}
648
651
}
0 commit comments