Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/unify.rs')
-rw-r--r--crates/hir-ty/src/infer/unify.rs32
1 files changed, 28 insertions, 4 deletions
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index 6a34c5b8e5..bb6e383e7d 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -7,7 +7,7 @@ use hir_def::{ExpressionStoreOwnerId, GenericParamId, TraitId};
use rustc_hash::FxHashSet;
use rustc_type_ir::{
TyVid, TypeFoldable, TypeVisitableExt,
- inherent::{GenericArg as _, IntoKind, Ty as _},
+ inherent::{Const as _, GenericArg as _, IntoKind, Ty as _},
solve::Certainty,
};
use smallvec::SmallVec;
@@ -17,9 +17,9 @@ use crate::{
InferenceDiagnostic, Span,
db::HirDatabase,
next_solver::{
- Canonical, ClauseKind, Const, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
- ParamEnv, Predicate, PredicateKind, Region, SolverDefId, Term, TraitRef, Ty, TyKind,
- TypingMode,
+ Canonical, ClauseKind, Const, ConstKind, DbInterner, ErrorGuaranteed, GenericArg,
+ GenericArgs, ParamEnv, Predicate, PredicateKind, Region, SolverDefId, Term, TraitRef, Ty,
+ TyKind, TypingMode,
fulfill::{FulfillmentCtxt, NextSolverError},
infer::{
DbInternerInferExt, InferCtxt, InferOk,
@@ -342,6 +342,30 @@ impl<'db> InferenceTable<'db> {
}
}
+ pub(crate) fn try_structurally_resolve_const(
+ &mut self,
+ sp: Span,
+ ct: Const<'db>,
+ ) -> Const<'db> {
+ let ct = self.resolve_vars_with_obligations(ct);
+
+ if let ConstKind::Unevaluated(..) = ct.kind() {
+ let result = self
+ .infer_ctxt
+ .at(&ObligationCause::new(sp), self.param_env)
+ .structurally_normalize_const(ct, &mut self.fulfillment_cx);
+ match result {
+ Ok(normalized_ct) => normalized_ct,
+ Err(errors) => {
+ self.trait_errors.extend(errors);
+ Const::new_error(self.interner(), ErrorGuaranteed)
+ }
+ }
+ } else {
+ ct
+ }
+ }
+
pub(crate) fn snapshot(&mut self) -> CombinedSnapshot {
self.infer_ctxt.start_snapshot()
}