@@ -675,11 +675,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
675
675
}
676
676
677
677
let stack = self . push_stack ( previous_stack, & obligation) ;
678
- let fresh_trait_pred = stack. fresh_trait_pred ;
678
+ let mut fresh_trait_pred = stack. fresh_trait_pred ;
679
+ let mut param_env = obligation. param_env ;
680
+
681
+ fresh_trait_pred = fresh_trait_pred. map_bound ( |mut pred| {
682
+ param_env = param_env. with_constness ( pred. constness . and ( param_env. constness ( ) ) ) ;
683
+ pred
684
+ } ) ;
679
685
680
686
debug ! ( ?fresh_trait_pred) ;
681
687
682
- if let Some ( result) = self . check_evaluation_cache ( obligation . param_env , fresh_trait_pred) {
688
+ if let Some ( result) = self . check_evaluation_cache ( param_env, fresh_trait_pred) {
683
689
debug ! ( ?result, "CACHE HIT" ) ;
684
690
return Ok ( result) ;
685
691
}
@@ -709,11 +715,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
709
715
let reached_depth = stack. reached_depth . get ( ) ;
710
716
if reached_depth >= stack. depth {
711
717
debug ! ( ?result, "CACHE MISS" ) ;
712
- self . insert_evaluation_cache ( obligation . param_env , fresh_trait_pred, dep_node, result) ;
718
+ self . insert_evaluation_cache ( param_env, fresh_trait_pred, dep_node, result) ;
713
719
714
720
stack. cache ( ) . on_completion ( stack. dfn , |fresh_trait_pred, provisional_result| {
715
721
self . insert_evaluation_cache (
716
- obligation . param_env ,
722
+ param_env,
717
723
fresh_trait_pred,
718
724
dep_node,
719
725
provisional_result. max ( result) ,
@@ -1200,7 +1206,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1200
1206
1201
1207
fn check_candidate_cache (
1202
1208
& mut self ,
1203
- param_env : ty:: ParamEnv < ' tcx > ,
1209
+ mut param_env : ty:: ParamEnv < ' tcx > ,
1204
1210
cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
1205
1211
) -> Option < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > {
1206
1212
// Neither the global nor local cache is aware of intercrate
@@ -1211,7 +1217,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1211
1217
return None ;
1212
1218
}
1213
1219
let tcx = self . tcx ( ) ;
1214
- let pred = cache_fresh_trait_pred. skip_binder ( ) ;
1220
+ let mut pred = cache_fresh_trait_pred. skip_binder ( ) ;
1221
+ param_env = param_env. with_constness ( pred. constness . and ( param_env. constness ( ) ) ) ;
1222
+
1215
1223
if self . can_use_global_caches ( param_env) {
1216
1224
if let Some ( res) = tcx. selection_cache . get ( & param_env. and ( pred) , tcx) {
1217
1225
return Some ( res) ;
@@ -1255,13 +1263,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1255
1263
1256
1264
fn insert_candidate_cache (
1257
1265
& mut self ,
1258
- param_env : ty:: ParamEnv < ' tcx > ,
1266
+ mut param_env : ty:: ParamEnv < ' tcx > ,
1259
1267
cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
1260
1268
dep_node : DepNodeIndex ,
1261
1269
candidate : SelectionResult < ' tcx , SelectionCandidate < ' tcx > > ,
1262
1270
) {
1263
1271
let tcx = self . tcx ( ) ;
1264
- let pred = cache_fresh_trait_pred. skip_binder ( ) ;
1272
+ let mut pred = cache_fresh_trait_pred. skip_binder ( ) ;
1273
+
1274
+ param_env = param_env. with_constness ( pred. constness . and ( param_env. constness ( ) ) ) ;
1265
1275
1266
1276
if !self . can_cache_candidate ( & candidate) {
1267
1277
debug ! ( ?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable" ) ;
0 commit comments