aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 7b6dfd61b..1eca4883d 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -41,10 +41,7 @@ use super::{
41 ApplicationTy, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor, 41 ApplicationTy, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor,
42 TypeWalk, Uncertain, 42 TypeWalk, Uncertain,
43}; 43};
44use crate::{ 44use crate::{db::HirDatabase, ty::infer::diagnostics::InferenceDiagnostic, VariantDef};
45 db::HirDatabase, ty::infer::diagnostics::InferenceDiagnostic, AssocItem, DefWithBody,
46 VariantDef,
47};
48 45
49macro_rules! ty_app { 46macro_rules! ty_app {
50 ($ctor:pat, $param:pat) => { 47 ($ctor:pat, $param:pat) => {
@@ -62,15 +59,15 @@ mod pat;
62mod coerce; 59mod coerce;
63 60
64/// The entry point of type inference. 61/// The entry point of type inference.
65pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { 62pub fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
66 let _p = profile("infer_query"); 63 let _p = profile("infer_query");
67 let resolver = DefWithBodyId::from(def).resolver(db); 64 let resolver = def.resolver(db);
68 let mut ctx = InferenceContext::new(db, def, resolver); 65 let mut ctx = InferenceContext::new(db, def, resolver);
69 66
70 match &def { 67 match def {
71 DefWithBody::Const(c) => ctx.collect_const(&db.const_data(c.id)), 68 DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)),
72 DefWithBody::Function(f) => ctx.collect_fn(&db.function_data(f.id)), 69 DefWithBodyId::FunctionId(f) => ctx.collect_fn(&db.function_data(f)),
73 DefWithBody::Static(s) => ctx.collect_const(&db.static_data(s.id)), 70 DefWithBodyId::StaticId(s) => ctx.collect_const(&db.static_data(s)),
74 } 71 }
75 72
76 ctx.infer_body(); 73 ctx.infer_body();
@@ -129,7 +126,7 @@ pub struct InferenceResult {
129 /// For each struct literal, records the variant it resolves to. 126 /// For each struct literal, records the variant it resolves to.
130 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>, 127 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>,
131 /// For each associated item record what it resolves to 128 /// For each associated item record what it resolves to
132 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItem>, 129 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>,
133 diagnostics: Vec<InferenceDiagnostic>, 130 diagnostics: Vec<InferenceDiagnostic>,
134 pub(super) type_of_expr: ArenaMap<ExprId, Ty>, 131 pub(super) type_of_expr: ArenaMap<ExprId, Ty>,
135 pub(super) type_of_pat: ArenaMap<PatId, Ty>, 132 pub(super) type_of_pat: ArenaMap<PatId, Ty>,
@@ -152,10 +149,10 @@ impl InferenceResult {
152 pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> { 149 pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> {
153 self.variant_resolutions.get(&id.into()).copied() 150 self.variant_resolutions.get(&id.into()).copied()
154 } 151 }
155 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<AssocItem> { 152 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<AssocItemId> {
156 self.assoc_resolutions.get(&id.into()).copied() 153 self.assoc_resolutions.get(&id.into()).copied()
157 } 154 }
158 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<AssocItem> { 155 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<AssocItemId> {
159 self.assoc_resolutions.get(&id.into()).copied() 156 self.assoc_resolutions.get(&id.into()).copied()
160 } 157 }
161 pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { 158 pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> {
@@ -191,7 +188,7 @@ impl Index<PatId> for InferenceResult {
191#[derive(Clone, Debug)] 188#[derive(Clone, Debug)]
192struct InferenceContext<'a, D: HirDatabase> { 189struct InferenceContext<'a, D: HirDatabase> {
193 db: &'a D, 190 db: &'a D,
194 owner: DefWithBody, 191 owner: DefWithBodyId,
195 body: Arc<Body>, 192 body: Arc<Body>,
196 resolver: Resolver, 193 resolver: Resolver,
197 var_unification_table: InPlaceUnificationTable<TypeVarId>, 194 var_unification_table: InPlaceUnificationTable<TypeVarId>,
@@ -209,7 +206,7 @@ struct InferenceContext<'a, D: HirDatabase> {
209} 206}
210 207
211impl<'a, D: HirDatabase> InferenceContext<'a, D> { 208impl<'a, D: HirDatabase> InferenceContext<'a, D> {
212 fn new(db: &'a D, owner: DefWithBody, resolver: Resolver) -> Self { 209 fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self {
213 InferenceContext { 210 InferenceContext {
214 result: InferenceResult::default(), 211 result: InferenceResult::default(),
215 var_unification_table: InPlaceUnificationTable::new(), 212 var_unification_table: InPlaceUnificationTable::new(),