@@ -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: \
@@ -1336,7 +1342,7 @@ enum ProjectionCacheEntry<'tcx> {
1336
1342
InProgress ,
1337
1343
Ambiguous ,
1338
1344
Error ,
1339
- NormalizedTy ( Ty < ' tcx > ) ,
1345
+ NormalizedTy ( NormalizedTy < ' tcx > ) ,
1340
1346
}
1341
1347
1342
1348
// NB: intentionally not Clone
@@ -1389,7 +1395,7 @@ impl<'tcx> ProjectionCache<'tcx> {
1389
1395
let fresh_key = if cacheable {
1390
1396
debug ! ( "ProjectionCacheEntry::complete: adding cache entry: key={:?}, value={:?}" ,
1391
1397
key, value) ;
1392
- self . map . insert ( key, ProjectionCacheEntry :: NormalizedTy ( value. value ) )
1398
+ self . map . insert ( key, ProjectionCacheEntry :: NormalizedTy ( value. clone ( ) ) )
1393
1399
} else {
1394
1400
debug ! ( "ProjectionCacheEntry::complete: cannot cache: key={:?}, value={:?}" ,
1395
1401
key, value) ;
0 commit comments