|
| 1 | +use rustc_middle::ty; |
| 2 | + |
1 | 3 | use crate::infer::canonical::OriginalQueryValues;
|
2 | 4 | use crate::infer::InferCtxt;
|
3 | 5 | use crate::traits::{
|
@@ -64,10 +66,28 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
64 | 66 | obligation: &PredicateObligation<'tcx>,
|
65 | 67 | ) -> Result<EvaluationResult, OverflowError> {
|
66 | 68 | let mut _orig_values = OriginalQueryValues::default();
|
67 |
| - let c_pred = self.canonicalize_query_keep_static( |
68 |
| - obligation.param_env.and(obligation.predicate), |
69 |
| - &mut _orig_values, |
70 |
| - ); |
| 69 | + |
| 70 | + let (param_env, predicate) = match obligation.predicate.kind().skip_binder() { |
| 71 | + ty::PredicateKind::Trait(mut pred) => { |
| 72 | + let orig_pred_constness = pred.constness; |
| 73 | + let env_constness = pred.constness.and(obligation.param_env.constness()); |
| 74 | + |
| 75 | + let predicate = if orig_pred_constness != pred.constness { |
| 76 | + self.tcx.mk_predicate( |
| 77 | + obligation.predicate.kind().rebind(ty::PredicateKind::Trait(pred)), |
| 78 | + ) |
| 79 | + } else { |
| 80 | + obligation.predicate |
| 81 | + }; |
| 82 | + |
| 83 | + (obligation.param_env.with_constness(env_constness), predicate) |
| 84 | + } |
| 85 | + // constness has no effect on the given predicate. |
| 86 | + _ => (obligation.param_env.without_const(), obligation.predicate), |
| 87 | + }; |
| 88 | + |
| 89 | + let c_pred = |
| 90 | + self.canonicalize_query_keep_static(param_env.and(predicate), &mut _orig_values); |
71 | 91 | // Run canonical query. If overflow occurs, rerun from scratch but this time
|
72 | 92 | // in standard trait query mode so that overflow is handled appropriately
|
73 | 93 | // within `SelectionContext`.
|
|
0 commit comments