Skip to content

Commit

Permalink
move code to InferCtxt method
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Aug 19, 2021
1 parent ab61e72 commit c2b61fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
16 changes: 16 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome}
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;
Expand Down Expand Up @@ -553,13 +552,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
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![]);
}
}
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use rustc_errors::ErrorReported;
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;
Expand Down Expand Up @@ -609,13 +608,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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);
}
}
Expand Down

0 comments on commit c2b61fb

Please sign in to comment.