@@ -462,13 +462,19 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
462
462
selcx. infcx ( ) . report_overflow_error ( & obligation, false ) ;
463
463
}
464
464
Err ( ProjectionCacheEntry :: NormalizedTy ( ty) ) => {
465
- // If we find the value in the cache, then the obligations
466
- // have already been returned from the previous entry (and
467
- // should therefore have been honored).
465
+ // If we find the value in the cache, then return it along
466
+ // with the obligations that went along with it. Note
467
+ // that, when using a fulfillment context, these
468
+ // obligations could in principle be ignored: they have
469
+ // already been registered when the cache entry was
470
+ // created (and hence the new ones will quickly be
471
+ // discarded as duplicated). But when doing trait
472
+ // evaluation this is not the case, and dropping the trait
473
+ // evaluations can causes ICEs (e.g. #43132).
468
474
debug ! ( "opt_normalize_projection_type: \
469
475
found normalized ty `{:?}`",
470
476
ty) ;
471
- return Some ( NormalizedTy { value : ty , obligations : vec ! [ ] } ) ;
477
+ return Some ( ty ) ;
472
478
}
473
479
Err ( ProjectionCacheEntry :: Error ) => {
474
480
debug ! ( "opt_normalize_projection_type: \
@@ -1326,7 +1332,7 @@ enum ProjectionCacheEntry<'tcx> {
1326
1332
InProgress ,
1327
1333
Ambiguous ,
1328
1334
Error ,
1329
- NormalizedTy ( Ty < ' tcx > ) ,
1335
+ NormalizedTy ( NormalizedTy < ' tcx > ) ,
1330
1336
}
1331
1337
1332
1338
// NB: intentionally not Clone
@@ -1374,7 +1380,7 @@ impl<'tcx> ProjectionCache<'tcx> {
1374
1380
fn complete ( & mut self , key : ty:: ProjectionTy < ' tcx > , value : & NormalizedTy < ' tcx > ) {
1375
1381
debug ! ( "ProjectionCacheEntry::complete: adding cache entry: key={:?}, value={:?}" ,
1376
1382
key, value) ;
1377
- let fresh_key = self . map . insert ( key, ProjectionCacheEntry :: NormalizedTy ( value. value ) ) ;
1383
+ let fresh_key = self . map . insert ( key, ProjectionCacheEntry :: NormalizedTy ( value. clone ( ) ) ) ;
1378
1384
assert ! ( !fresh_key, "never started projecting `{:?}`" , key) ;
1379
1385
}
1380
1386
0 commit comments