1
Fork 0

erase region in ParamEnvAnd and make ConstUnifyCtxt private

This commit is contained in:
b-naber 2022-03-22 16:13:28 +01:00
parent fe69a5cf0c
commit 11a70dbc8a
3 changed files with 12 additions and 13 deletions

View file

@ -702,11 +702,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
return false; return false;
} }
let erased_args = self.tcx.erase_regions((a, b)); let param_env_and = param_env.and((a, b));
let erased_param_env = self.tcx.erase_regions(param_env); let erased = self.tcx.erase_regions(param_env_and);
debug!("after erase_regions args: {:?}, param_env: {:?}", erased_args, param_env); 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 { pub fn is_in_snapshot(&self) -> bool {

View file

@ -41,7 +41,10 @@ impl<'tcx> TyCtxt<'tcx> {
) -> EvalToConstValueResult<'tcx> { ) -> EvalToConstValueResult<'tcx> {
// Cannot resolve `Unevaluated` constants that contain inference // Cannot resolve `Unevaluated` constants that contain inference
// variables. We reject those here since `resolve_opt_const_arg` // 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() { if ct.substs.has_infer_types_or_consts() {
bug!("did not expect inference variables here"); bug!("did not expect inference variables here");
} }

View file

@ -195,7 +195,7 @@ fn satisfied_from_param_env<'tcx>(
match pred.kind().skip_binder() { match pred.kind().skip_binder() {
ty::PredicateKind::ConstEvaluatable(uv) => { ty::PredicateKind::ConstEvaluatable(uv) => {
if let Some(b_ct) = AbstractConst::new(tcx, 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 // Try to unify with each subtree in the AbstractConst to allow for
// `N + 1` being const evaluatable even if theres only a `ConstEvaluatable` // `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(a) = AbstractConst::new(tcx, a)? {
if let Some(b) = AbstractConst::new(tcx, b)? { 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)); return Ok(const_unify_ctxt.try_unify(a, b));
} }
} }
@ -625,22 +625,18 @@ where
recurse(tcx, ct, &mut f) recurse(tcx, ct, &mut f)
} }
pub(super) struct ConstUnifyCtxt<'tcx> { struct ConstUnifyCtxt<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
} }
impl<'tcx> ConstUnifyCtxt<'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 // Substitutes generics repeatedly to allow AbstractConsts to unify where a
// ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g. // 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)])])] // Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])]
#[inline] #[inline]
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
pub(super) fn try_replace_substs_in_root( fn try_replace_substs_in_root(
&self, &self,
mut abstr_const: AbstractConst<'tcx>, mut abstr_const: AbstractConst<'tcx>,
) -> Option<AbstractConst<'tcx>> { ) -> Option<AbstractConst<'tcx>> {