@@ -462,13 +462,19 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
462462 selcx. infcx ( ) . report_overflow_error ( & obligation, false ) ;
463463 }
464464 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).
468474 debug ! ( "opt_normalize_projection_type: \
469475 found normalized ty `{:?}`",
470476 ty) ;
471- return Some ( NormalizedTy { value : ty , obligations : vec ! [ ] } ) ;
477+ return Some ( ty ) ;
472478 }
473479 Err ( ProjectionCacheEntry :: Error ) => {
474480 debug ! ( "opt_normalize_projection_type: \
@@ -1326,7 +1332,7 @@ enum ProjectionCacheEntry<'tcx> {
13261332 InProgress ,
13271333 Ambiguous ,
13281334 Error ,
1329- NormalizedTy ( Ty < ' tcx > ) ,
1335+ NormalizedTy ( NormalizedTy < ' tcx > ) ,
13301336}
13311337
13321338// NB: intentionally not Clone
@@ -1374,7 +1380,7 @@ impl<'tcx> ProjectionCache<'tcx> {
13741380 fn complete ( & mut self , key : ty:: ProjectionTy < ' tcx > , value : & NormalizedTy < ' tcx > ) {
13751381 debug ! ( "ProjectionCacheEntry::complete: adding cache entry: key={:?}, value={:?}" ,
13761382 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 ( ) ) ) ;
13781384 assert ! ( !fresh_key, "never started projecting `{:?}`" , key) ;
13791385 }
13801386
0 commit comments