Skip to content

Commit 11a70db

Browse files
committed
erase region in ParamEnvAnd and make ConstUnifyCtxt private
1 parent fe69a5c commit 11a70db

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

compiler/rustc_infer/src/infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
702702
return false;
703703
}
704704

705-
let erased_args = self.tcx.erase_regions((a, b));
706-
let erased_param_env = self.tcx.erase_regions(param_env);
707-
debug!("after erase_regions args: {:?}, param_env: {:?}", erased_args, param_env);
705+
let param_env_and = param_env.and((a, b));
706+
let erased = self.tcx.erase_regions(param_env_and);
707+
debug!("after erase_regions: {:?}", erased);
708708

709-
self.tcx.try_unify_abstract_consts(erased_param_env.and(erased_args))
709+
self.tcx.try_unify_abstract_consts(erased)
710710
}
711711

712712
pub fn is_in_snapshot(&self) -> bool {

compiler/rustc_middle/src/mir/interpret/queries.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ impl<'tcx> TyCtxt<'tcx> {
4141
) -> EvalToConstValueResult<'tcx> {
4242
// Cannot resolve `Unevaluated` constants that contain inference
4343
// variables. We reject those here since `resolve_opt_const_arg`
44-
// would fail otherwise
44+
// would fail otherwise.
45+
//
46+
// When trying to evaluate constants containing inference variables,
47+
// use `Infcx::const_eval_resolve` instead.
4548
if ct.substs.has_infer_types_or_consts() {
4649
bug!("did not expect inference variables here");
4750
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn satisfied_from_param_env<'tcx>(
195195
match pred.kind().skip_binder() {
196196
ty::PredicateKind::ConstEvaluatable(uv) => {
197197
if let Some(b_ct) = AbstractConst::new(tcx, uv)? {
198-
let const_unify_ctxt = ConstUnifyCtxt::new(tcx, param_env);
198+
let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env };
199199

200200
// Try to unify with each subtree in the AbstractConst to allow for
201201
// `N + 1` being const evaluatable even if theres only a `ConstEvaluatable`
@@ -579,7 +579,7 @@ pub(super) fn try_unify_abstract_consts<'tcx>(
579579
(|| {
580580
if let Some(a) = AbstractConst::new(tcx, a)? {
581581
if let Some(b) = AbstractConst::new(tcx, b)? {
582-
let const_unify_ctxt = ConstUnifyCtxt::new(tcx, param_env);
582+
let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env };
583583
return Ok(const_unify_ctxt.try_unify(a, b));
584584
}
585585
}
@@ -625,22 +625,18 @@ where
625625
recurse(tcx, ct, &mut f)
626626
}
627627

628-
pub(super) struct ConstUnifyCtxt<'tcx> {
628+
struct ConstUnifyCtxt<'tcx> {
629629
tcx: TyCtxt<'tcx>,
630630
param_env: ty::ParamEnv<'tcx>,
631631
}
632632

633633
impl<'tcx> ConstUnifyCtxt<'tcx> {
634-
pub(super) fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
635-
ConstUnifyCtxt { tcx, param_env }
636-
}
637-
638634
// Substitutes generics repeatedly to allow AbstractConsts to unify where a
639635
// ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g.
640636
// Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])]
641637
#[inline]
642638
#[instrument(skip(self), level = "debug")]
643-
pub(super) fn try_replace_substs_in_root(
639+
fn try_replace_substs_in_root(
644640
&self,
645641
mut abstr_const: AbstractConst<'tcx>,
646642
) -> Option<AbstractConst<'tcx>> {

0 commit comments

Comments
 (0)