Skip to content

Commit 2bea3b3

Browse files
committed
Remap predicate/env constness before querying
1 parent 42963f4 commit 2bea3b3

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rustc_middle::ty;
2+
13
use crate::infer::canonical::OriginalQueryValues;
24
use crate::infer::InferCtxt;
35
use crate::traits::{
@@ -64,10 +66,28 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
6466
obligation: &PredicateObligation<'tcx>,
6567
) -> Result<EvaluationResult, OverflowError> {
6668
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);
7191
// Run canonical query. If overflow occurs, rerun from scratch but this time
7292
// in standard trait query mode so that overflow is handled appropriately
7393
// within `SelectionContext`.

0 commit comments

Comments
 (0)