@@ -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;
@@ -1557,6 +1558,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15571558 if self . is_intercrate ( ) {
15581559 return None ;
15591560 }
1561+
1562+ // Opaque types are not part of the global cache key, so we'd be caching and loading
1563+ // values, even though we don't have all the information that went into them.
1564+ if !self . infcx . defining_opaque_types ( ) . is_empty ( ) {
1565+ return None ;
1566+ }
1567+
15601568 let tcx = self . tcx ( ) ;
15611569 let pred = cache_fresh_trait_pred. skip_binder ( ) ;
15621570
@@ -1595,6 +1603,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15951603 if self . is_intercrate ( ) {
15961604 return false ;
15971605 }
1606+ // Opaque types are not part of the global cache key, so we'd be caching and loading
1607+ // values, even though we don't have all the information that went into them.
1608+ if !self . infcx . defining_opaque_types ( ) . is_empty ( ) {
1609+ return false ;
1610+ }
15981611 match result {
15991612 Ok ( Some ( SelectionCandidate :: ParamCandidate ( trait_ref) ) ) => !trait_ref. has_infer ( ) ,
16001613 _ => true ,
0 commit comments