Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/diagnostics.rs')
-rw-r--r--crates/hir-ty/src/infer/diagnostics.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/crates/hir-ty/src/infer/diagnostics.rs b/crates/hir-ty/src/infer/diagnostics.rs
index 50feab8dd4..dd0efea4d7 100644
--- a/crates/hir-ty/src/infer/diagnostics.rs
+++ b/crates/hir-ty/src/infer/diagnostics.rs
@@ -6,21 +6,24 @@ use std::cell::{OnceCell, RefCell};
use std::ops::{Deref, DerefMut};
use either::Either;
-use hir_def::expr_store::ExpressionStore;
use hir_def::expr_store::path::Path;
use hir_def::{ExpressionStoreOwnerId, GenericDefId};
+use hir_def::{expr_store::ExpressionStore, type_ref::TypeRefId};
use hir_def::{hir::ExprOrPatId, resolver::Resolver};
use la_arena::{Idx, RawIdx};
+use rustc_hash::FxHashMap;
use thin_vec::ThinVec;
use crate::{
- InferenceDiagnostic, InferenceTyDiagnosticSource, TyLoweringDiagnostic,
+ InferenceDiagnostic, InferenceTyDiagnosticSource, Span, TyLoweringDiagnostic,
db::{AnonConstId, HirDatabase},
generics::Generics,
+ infer::unify::InferenceTable,
lower::{
ForbidParamsAfterReason, LifetimeElisionKind, TyLoweringContext, TyLoweringInferVarsCtx,
path::{PathDiagnosticCallback, PathLoweringContext},
},
+ next_solver::{Const, Region, StoredTy, Ty},
};
// Unfortunately, this struct needs to use interior mutability (but we encapsulate it)
@@ -55,6 +58,33 @@ pub(crate) struct PathDiagnosticCallbackData<'a> {
diagnostics: &'a Diagnostics,
}
+pub(super) struct InferenceTyLoweringVarsCtx<'a, 'db> {
+ pub(super) table: &'a mut InferenceTable<'db>,
+ pub(super) type_of_type_placeholder: &'a mut FxHashMap<TypeRefId, StoredTy>,
+}
+
+impl<'db> TyLoweringInferVarsCtx<'db> for InferenceTyLoweringVarsCtx<'_, 'db> {
+ fn next_ty_var(&mut self, span: Span) -> Ty<'db> {
+ let ty = self.table.infer_ctxt.next_ty_var(span);
+
+ if let Span::TypeRefId(type_ref) = span {
+ self.type_of_type_placeholder.insert(type_ref, ty.store());
+ }
+
+ ty
+ }
+ fn next_const_var(&mut self, span: Span) -> Const<'db> {
+ self.table.infer_ctxt.next_const_var(span)
+ }
+ fn next_region_var(&mut self, span: Span) -> Region<'db> {
+ self.table.infer_ctxt.next_region_var(span)
+ }
+
+ fn as_table(&mut self) -> Option<&mut InferenceTable<'db>> {
+ Some(self.table)
+ }
+}
+
pub(super) struct InferenceTyLoweringContext<'db, 'a> {
ctx: TyLoweringContext<'db, 'a>,
diagnostics: &'a Diagnostics,
@@ -75,7 +105,7 @@ impl<'db, 'a> InferenceTyLoweringContext<'db, 'a> {
generics: &'a OnceCell<Generics<'db>>,
lifetime_elision: LifetimeElisionKind<'db>,
allow_using_generic_params: bool,
- infer_vars: Option<TyLoweringInferVarsCtx<'a, 'db>>,
+ infer_vars: Option<&'a mut dyn TyLoweringInferVarsCtx<'db>>,
defined_anon_consts: &'a RefCell<ThinVec<AnonConstId>>,
) -> Self {
let mut ctx = TyLoweringContext::new(