Skip to content

Commit

Permalink
erase region in ParamEnvAnd and make ConstUnifyCtxt private
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Mar 22, 2022
1 parent fe69a5c commit 11a70db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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<AbstractConst<'tcx>> {
Expand Down

0 comments on commit 11a70db

Please sign in to comment.