@@ -675,11 +675,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
675675 }
676676
677677 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+ } ) ;
679685
680686 debug ! ( ?fresh_trait_pred) ;
681687
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) {
683689 debug ! ( ?result, "CACHE HIT" ) ;
684690 return Ok ( result) ;
685691 }
@@ -709,11 +715,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
709715 let reached_depth = stack. reached_depth . get ( ) ;
710716 if reached_depth >= stack. depth {
711717 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) ;
713719
714720 stack. cache ( ) . on_completion ( stack. dfn , |fresh_trait_pred, provisional_result| {
715721 self . insert_evaluation_cache (
716- obligation . param_env ,
722+ param_env,
717723 fresh_trait_pred,
718724 dep_node,
719725 provisional_result. max ( result) ,
@@ -1200,7 +1206,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12001206
12011207 fn check_candidate_cache (
12021208 & mut self ,
1203- param_env : ty:: ParamEnv < ' tcx > ,
1209+ mut param_env : ty:: ParamEnv < ' tcx > ,
12041210 cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
12051211 ) -> Option < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > {
12061212 // Neither the global nor local cache is aware of intercrate
@@ -1211,7 +1217,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12111217 return None ;
12121218 }
12131219 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+
12151223 if self . can_use_global_caches ( param_env) {
12161224 if let Some ( res) = tcx. selection_cache . get ( & param_env. and ( pred) , tcx) {
12171225 return Some ( res) ;
@@ -1255,13 +1263,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12551263
12561264 fn insert_candidate_cache (
12571265 & mut self ,
1258- param_env : ty:: ParamEnv < ' tcx > ,
1266+ mut param_env : ty:: ParamEnv < ' tcx > ,
12591267 cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
12601268 dep_node : DepNodeIndex ,
12611269 candidate : SelectionResult < ' tcx , SelectionCandidate < ' tcx > > ,
12621270 ) {
12631271 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 ( ) ) ) ;
12651275
12661276 if !self . can_cache_candidate ( & candidate) {
12671277 debug ! ( ?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable" ) ;
0 commit comments