@@ -49,6 +49,7 @@ use rustc_middle::ty::{self, PolyProjectionPredicate, Upcast};
49
49
use rustc_middle:: ty:: { Ty , TyCtxt , TypeFoldable , TypeVisitableExt } ;
50
50
use rustc_span:: symbol:: sym;
51
51
use rustc_span:: Symbol ;
52
+ use rustc_type_ir:: InferCtxtLike as _;
52
53
53
54
use std:: cell:: { Cell , RefCell } ;
54
55
use std:: cmp;
@@ -1557,6 +1558,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1557
1558
if self . is_intercrate ( ) {
1558
1559
return None ;
1559
1560
}
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
+
1560
1568
let tcx = self . tcx ( ) ;
1561
1569
let pred = cache_fresh_trait_pred. skip_binder ( ) ;
1562
1570
@@ -1595,6 +1603,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1595
1603
if self . is_intercrate ( ) {
1596
1604
return false ;
1597
1605
}
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
+ }
1598
1611
match result {
1599
1612
Ok ( Some ( SelectionCandidate :: ParamCandidate ( trait_ref) ) ) => !trait_ref. has_infer ( ) ,
1600
1613
_ => true ,
0 commit comments