diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index a779e38a169..2886d921c70 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -702,11 +702,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { return false; } - let erased_args = self.tcx.erase_regions((a, b)); - let erased_param_env = self.tcx.erase_regions(param_env); - debug!("after erase_regions args: {:?}, param_env: {:?}", erased_args, param_env); + let param_env_and = param_env.and((a, b)); + let erased = self.tcx.erase_regions(param_env_and); + debug!("after erase_regions: {:?}", erased); - self.tcx.try_unify_abstract_consts(erased_param_env.and(erased_args)) + self.tcx.try_unify_abstract_consts(erased) } pub fn is_in_snapshot(&self) -> bool { diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index 639a9bc600a..7e5989b4112 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -41,7 +41,10 @@ impl<'tcx> TyCtxt<'tcx> { ) -> EvalToConstValueResult<'tcx> { // Cannot resolve `Unevaluated` constants that contain inference // variables. We reject those here since `resolve_opt_const_arg` - // would fail otherwise + // would fail otherwise. + // + // When trying to evaluate constants containing inference variables, + // use `Infcx::const_eval_resolve` instead. if ct.substs.has_infer_types_or_consts() { bug!("did not expect inference variables here"); } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 93810cb00cf..4fb186ab0ef 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -195,7 +195,7 @@ fn satisfied_from_param_env<'tcx>( match pred.kind().skip_binder() { ty::PredicateKind::ConstEvaluatable(uv) => { if let Some(b_ct) = AbstractConst::new(tcx, uv)? { - let const_unify_ctxt = ConstUnifyCtxt::new(tcx, param_env); + let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env }; // Try to unify with each subtree in the AbstractConst to allow for // `N + 1` being const evaluatable even if theres only a `ConstEvaluatable` @@ -579,7 +579,7 @@ pub(super) fn try_unify_abstract_consts<'tcx>( (|| { if let Some(a) = AbstractConst::new(tcx, a)? { if let Some(b) = AbstractConst::new(tcx, b)? { - let const_unify_ctxt = ConstUnifyCtxt::new(tcx, param_env); + let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env }; return Ok(const_unify_ctxt.try_unify(a, b)); } } @@ -625,22 +625,18 @@ where recurse(tcx, ct, &mut f) } -pub(super) struct ConstUnifyCtxt<'tcx> { +struct ConstUnifyCtxt<'tcx> { tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, } impl<'tcx> ConstUnifyCtxt<'tcx> { - pub(super) fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self { - ConstUnifyCtxt { tcx, param_env } - } - // Substitutes generics repeatedly to allow AbstractConsts to unify where a // ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g. // Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])] #[inline] #[instrument(skip(self), level = "debug")] - pub(super) fn try_replace_substs_in_root( + fn try_replace_substs_in_root( &self, mut abstr_const: AbstractConst<'tcx>, ) -> Option> {