@@ -6,21 +6,24 @@ use std::cell::{OnceCell, RefCell};
66use std:: ops:: { Deref , DerefMut } ;
77
88use either:: Either ;
9- use hir_def:: expr_store:: ExpressionStore ;
109use hir_def:: expr_store:: path:: Path ;
1110use hir_def:: { ExpressionStoreOwnerId , GenericDefId } ;
11+ use hir_def:: { expr_store:: ExpressionStore , type_ref:: TypeRefId } ;
1212use hir_def:: { hir:: ExprOrPatId , resolver:: Resolver } ;
1313use la_arena:: { Idx , RawIdx } ;
14+ use rustc_hash:: FxHashMap ;
1415use thin_vec:: ThinVec ;
1516
1617use crate :: {
17- InferenceDiagnostic , InferenceTyDiagnosticSource , TyLoweringDiagnostic ,
18+ InferenceDiagnostic , InferenceTyDiagnosticSource , Span , TyLoweringDiagnostic ,
1819 db:: { AnonConstId , HirDatabase } ,
1920 generics:: Generics ,
21+ infer:: unify:: InferenceTable ,
2022 lower:: {
2123 ForbidParamsAfterReason , LifetimeElisionKind , TyLoweringContext , TyLoweringInferVarsCtx ,
2224 path:: { PathDiagnosticCallback , PathLoweringContext } ,
2325 } ,
26+ next_solver:: { Const , Region , StoredTy , Ty } ,
2427} ;
2528
2629// Unfortunately, this struct needs to use interior mutability (but we encapsulate it)
@@ -55,6 +58,33 @@ pub(crate) struct PathDiagnosticCallbackData<'a> {
5558 diagnostics : & ' a Diagnostics ,
5659}
5760
61+ pub ( super ) struct InferenceTyLoweringVarsCtx < ' a , ' db > {
62+ pub ( super ) table : & ' a mut InferenceTable < ' db > ,
63+ pub ( super ) type_of_type_placeholder : & ' a mut FxHashMap < TypeRefId , StoredTy > ,
64+ }
65+
66+ impl < ' db > TyLoweringInferVarsCtx < ' db > for InferenceTyLoweringVarsCtx < ' _ , ' db > {
67+ fn next_ty_var ( & mut self , span : Span ) -> Ty < ' db > {
68+ let ty = self . table . infer_ctxt . next_ty_var ( span) ;
69+
70+ if let Span :: TypeRefId ( type_ref) = span {
71+ self . type_of_type_placeholder . insert ( type_ref, ty. store ( ) ) ;
72+ }
73+
74+ ty
75+ }
76+ fn next_const_var ( & mut self , span : Span ) -> Const < ' db > {
77+ self . table . infer_ctxt . next_const_var ( span)
78+ }
79+ fn next_region_var ( & mut self , span : Span ) -> Region < ' db > {
80+ self . table . infer_ctxt . next_region_var ( span)
81+ }
82+
83+ fn as_table ( & mut self ) -> Option < & mut InferenceTable < ' db > > {
84+ Some ( self . table )
85+ }
86+ }
87+
5888pub ( super ) struct InferenceTyLoweringContext < ' db , ' a > {
5989 ctx : TyLoweringContext < ' db , ' a > ,
6090 diagnostics : & ' a Diagnostics ,
@@ -75,7 +105,7 @@ impl<'db, 'a> InferenceTyLoweringContext<'db, 'a> {
75105 generics : & ' a OnceCell < Generics < ' db > > ,
76106 lifetime_elision : LifetimeElisionKind < ' db > ,
77107 allow_using_generic_params : bool ,
78- infer_vars : Option < TyLoweringInferVarsCtx < ' a , ' db > > ,
108+ infer_vars : Option < & ' a mut dyn TyLoweringInferVarsCtx < ' db > > ,
79109 defined_anon_consts : & ' a RefCell < ThinVec < AnonConstId > > ,
80110 ) -> Self {
81111 let mut ctx = TyLoweringContext :: new (
0 commit comments