move code to InferCtxt method

This commit is contained in:
Ellen 2021-08-19 21:04:04 +01:00
parent ab61e722ee
commit c2b61fbafe
3 changed files with 18 additions and 16 deletions

View File

@ -670,6 +670,22 @@ pub struct CombinedSnapshot<'a, 'tcx> {
}
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// calls `tcx.try_unify_abstract_consts` after
/// canonicalizing the consts.
pub fn try_unify_abstract_consts(
&self,
a: ty::Unevaluated<'tcx>,
b: ty::Unevaluated<'tcx>,
) -> bool {
let canonical = self.canonicalize_query(
((a.def, a.substs), (b.def, b.substs)),
&mut OriginalQueryValues::default(),
);
debug!("canonical consts: {:?}", &canonical.value);
self.tcx.try_unify_abstract_consts(canonical.value)
}
pub fn is_in_snapshot(&self) -> bool {
self.in_snapshot.get()
}

View File

@ -4,7 +4,6 @@
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_infer::infer::canonical::OriginalQueryValues;
use rustc_infer::traits::{SelectionError, TraitEngine, TraitEngineExt as _, TraitObligation};
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
use rustc_middle::mir::interpret::ErrorHandled;
@ -553,13 +552,7 @@ fn progress_changed_obligations(
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
(c1.val, c2.val)
{
let canonical = infcx.canonicalize_query(
((a.def, a.substs), (b.def, b.substs)),
&mut OriginalQueryValues::default(),
);
debug!("canonical consts: {:?}", &canonical.value);
if self.selcx.tcx().try_unify_abstract_consts(canonical.value) {
if infcx.try_unify_abstract_consts(a, b) {
return ProcessResult::Changed(vec![]);
}
}

View File

@ -33,7 +33,6 @@
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Constness;
use rustc_infer::infer::canonical::OriginalQueryValues;
use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
@ -609,13 +608,7 @@ fn evaluate_predicate_recursively<'o>(
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
(c1.val, c2.val)
{
let canonical = self.infcx.canonicalize_query(
((a.def, a.substs), (b.def, b.substs)),
&mut OriginalQueryValues::default(),
);
debug!("canonical consts: {:?}", &canonical.value);
if self.tcx().try_unify_abstract_consts(canonical.value) {
if self.infcx.try_unify_abstract_consts(a, b) {
return Ok(EvaluatedToOk);
}
}