@@ -275,11 +275,13 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
275
275
}
276
276
277
277
impl < ' cx , ' gcx , ' tcx > TypeFolder < ' gcx , ' tcx > for Canonicalizer < ' cx , ' gcx , ' tcx > {
278
+ type Error = !;
279
+
278
280
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' b , ' gcx , ' tcx > {
279
281
self . tcx
280
282
}
281
283
282
- fn fold_binder < T > ( & mut self , t : & ty:: Binder < T > ) -> ty:: Binder < T >
284
+ fn fold_binder < T > ( & mut self , t : & ty:: Binder < T > ) -> Result < ty:: Binder < T > , ! >
283
285
where T : TypeFoldable < ' tcx >
284
286
{
285
287
self . binder_index . shift_in ( 1 ) ;
@@ -288,8 +290,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
288
290
t
289
291
}
290
292
291
- fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
292
- match * r {
293
+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , ! > {
294
+ Ok ( match * r {
293
295
ty:: ReLateBound ( index, ..) => {
294
296
if index >= self . binder_index {
295
297
bug ! ( "escaping late bound region during canonicalization" )
@@ -324,10 +326,10 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
324
326
ty:: ReClosureBound ( ..) => {
325
327
bug ! ( "closure bound region encountered during canonicalization" )
326
328
}
327
- }
329
+ } )
328
330
}
329
331
330
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
332
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
331
333
match t. sty {
332
334
ty:: Infer ( ty:: TyVar ( vid) ) => {
333
335
debug ! ( "canonical: type var found with vid {:?}" , vid) ;
@@ -345,48 +347,48 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
345
347
// FIXME: perf problem described in #55921.
346
348
ui = ty:: UniverseIndex :: ROOT ;
347
349
}
348
- self . canonicalize_ty_var (
350
+ Ok ( self . canonicalize_ty_var (
349
351
CanonicalVarInfo {
350
352
kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
351
353
} ,
352
354
t
353
- )
355
+ ) )
354
356
}
355
357
}
356
358
}
357
359
358
- ty:: Infer ( ty:: IntVar ( _) ) => self . canonicalize_ty_var (
360
+ ty:: Infer ( ty:: IntVar ( _) ) => Ok ( self . canonicalize_ty_var (
359
361
CanonicalVarInfo {
360
362
kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int )
361
363
} ,
362
364
t
363
- ) ,
365
+ ) ) ,
364
366
365
- ty:: Infer ( ty:: FloatVar ( _) ) => self . canonicalize_ty_var (
367
+ ty:: Infer ( ty:: FloatVar ( _) ) => Ok ( self . canonicalize_ty_var (
366
368
CanonicalVarInfo {
367
369
kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float )
368
370
} ,
369
371
t
370
- ) ,
372
+ ) ) ,
371
373
372
374
ty:: Infer ( ty:: FreshTy ( _) )
373
375
| ty:: Infer ( ty:: FreshIntTy ( _) )
374
376
| ty:: Infer ( ty:: FreshFloatTy ( _) ) => {
375
377
bug ! ( "encountered a fresh type during canonicalization" )
376
378
}
377
379
378
- ty:: Placeholder ( placeholder) => self . canonicalize_ty_var (
380
+ ty:: Placeholder ( placeholder) => Ok ( self . canonicalize_ty_var (
379
381
CanonicalVarInfo {
380
382
kind : CanonicalVarKind :: PlaceholderTy ( placeholder)
381
383
} ,
382
384
t
383
- ) ,
385
+ ) ) ,
384
386
385
387
ty:: Bound ( debruijn, _) => {
386
388
if debruijn >= self . binder_index {
387
389
bug ! ( "escaping bound type during canonicalization" )
388
390
} else {
389
- t
391
+ Ok ( t )
390
392
}
391
393
}
392
394
@@ -418,7 +420,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
418
420
if t. flags . intersects ( self . needs_canonical_flags ) {
419
421
t. super_fold_with ( self )
420
422
} else {
421
- t
423
+ Ok ( t )
422
424
}
423
425
}
424
426
}
@@ -476,7 +478,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
476
478
indices : FxHashMap :: default ( ) ,
477
479
binder_index : ty:: INNERMOST ,
478
480
} ;
479
- let out_value = value. fold_with ( & mut canonicalizer) ;
481
+ let Ok ( out_value) = value. fold_with ( & mut canonicalizer) ;
480
482
481
483
// Once we have canonicalized `out_value`, it should not
482
484
// contain anything that ties it to this inference context
@@ -618,7 +620,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
618
620
let infcx = self . infcx . expect ( "encountered ty-var without infcx" ) ;
619
621
let bound_to = infcx. shallow_resolve ( ty_var) ;
620
622
if bound_to != ty_var {
621
- self . fold_ty ( bound_to)
623
+ self . fold_ty ( bound_to) . unwrap_or_else ( | e : !| e )
622
624
} else {
623
625
let var = self . canonical_var ( info, ty_var. into ( ) ) ;
624
626
self . tcx ( ) . mk_ty ( ty:: Bound ( self . binder_index , var. into ( ) ) )
0 commit comments