@@ -49,6 +49,7 @@ use rustc_middle::ty::{self, PolyProjectionPredicate, Upcast};
4949use rustc_middle:: ty:: { Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
5050use rustc_span:: symbol:: sym;
5151use rustc_span:: Symbol ;
52+ use rustc_type_ir:: InferCtxtLike as _;
5253
5354use std:: cell:: { Cell , RefCell } ;
5455use std:: cmp;
@@ -1559,13 +1560,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15591560 }
15601561 let tcx = self . tcx ( ) ;
15611562 let pred = cache_fresh_trait_pred. skip_binder ( ) ;
1563+ let opaques = self . infcx . defining_opaque_types ( ) ;
15621564
15631565 if self . can_use_global_caches ( param_env) {
1564- if let Some ( res) = tcx. selection_cache . get ( & ( param_env, pred) , tcx) {
1566+ if let Some ( res) = tcx. selection_cache . get ( & ( opaques , param_env, pred) , tcx) {
15651567 return Some ( res) ;
15661568 }
15671569 }
1568- self . infcx . selection_cache . get ( & ( param_env, pred) , tcx)
1570+ self . infcx . selection_cache . get ( & ( opaques , param_env, pred) , tcx)
15691571 }
15701572
15711573 /// Determines whether can we safely cache the result
@@ -1611,6 +1613,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16111613 ) {
16121614 let tcx = self . tcx ( ) ;
16131615 let pred = cache_fresh_trait_pred. skip_binder ( ) ;
1616+ let opaques = self . infcx . defining_opaque_types ( ) ;
16141617
16151618 if !self . can_cache_candidate ( & candidate) {
16161619 debug ! ( ?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable" ) ;
@@ -1624,14 +1627,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16241627 if !candidate. has_infer ( ) {
16251628 debug ! ( ?pred, ?candidate, "insert_candidate_cache global" ) ;
16261629 // This may overwrite the cache with the same value.
1627- tcx. selection_cache . insert ( ( param_env, pred) , dep_node, candidate) ;
1630+ tcx. selection_cache . insert ( ( opaques , param_env, pred) , dep_node, candidate) ;
16281631 return ;
16291632 }
16301633 }
16311634 }
16321635
16331636 debug ! ( ?pred, ?candidate, "insert_candidate_cache local" ) ;
1634- self . infcx . selection_cache . insert ( ( param_env, pred) , dep_node, candidate) ;
1637+ self . infcx . selection_cache . insert ( ( opaques , param_env, pred) , dep_node, candidate) ;
16351638 }
16361639
16371640 /// Looks at the item bounds of the projection or opaque type.
0 commit comments