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.rs11
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs8
2 files changed, 9 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 2370e8d4f..f17c6c614 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -43,7 +43,7 @@ use crate::{
43 expr::{BindingAnnotation, Body, ExprId, PatId}, 43 expr::{BindingAnnotation, Body, ExprId, PatId},
44 resolve::{Resolver, TypeNs}, 44 resolve::{Resolver, TypeNs},
45 ty::infer::diagnostics::InferenceDiagnostic, 45 ty::infer::diagnostics::InferenceDiagnostic,
46 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, 46 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, Path, StructField,
47}; 47};
48 48
49macro_rules! ty_app { 49macro_rules! ty_app {
@@ -64,9 +64,8 @@ mod coerce;
64/// The entry point of type inference. 64/// The entry point of type inference.
65pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { 65pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> {
66 let _p = profile("infer_query"); 66 let _p = profile("infer_query");
67 let body = def.body(db);
68 let resolver = def.resolver(db); 67 let resolver = def.resolver(db);
69 let mut ctx = InferenceContext::new(db, body, resolver); 68 let mut ctx = InferenceContext::new(db, def, resolver);
70 69
71 match def { 70 match def {
72 DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)), 71 DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)),
@@ -187,6 +186,7 @@ impl Index<PatId> for InferenceResult {
187#[derive(Clone, Debug)] 186#[derive(Clone, Debug)]
188struct InferenceContext<'a, D: HirDatabase> { 187struct InferenceContext<'a, D: HirDatabase> {
189 db: &'a D, 188 db: &'a D,
189 owner: DefWithBody,
190 body: Arc<Body>, 190 body: Arc<Body>,
191 resolver: Resolver, 191 resolver: Resolver,
192 var_unification_table: InPlaceUnificationTable<TypeVarId>, 192 var_unification_table: InPlaceUnificationTable<TypeVarId>,
@@ -204,7 +204,7 @@ struct InferenceContext<'a, D: HirDatabase> {
204} 204}
205 205
206impl<'a, D: HirDatabase> InferenceContext<'a, D> { 206impl<'a, D: HirDatabase> InferenceContext<'a, D> {
207 fn new(db: &'a D, body: Arc<Body>, resolver: Resolver) -> Self { 207 fn new(db: &'a D, owner: DefWithBody, resolver: Resolver) -> Self {
208 InferenceContext { 208 InferenceContext {
209 result: InferenceResult::default(), 209 result: InferenceResult::default(),
210 var_unification_table: InPlaceUnificationTable::new(), 210 var_unification_table: InPlaceUnificationTable::new(),
@@ -213,7 +213,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
213 trait_env: lower::trait_env(db, &resolver), 213 trait_env: lower::trait_env(db, &resolver),
214 coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), 214 coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver),
215 db, 215 db,
216 body, 216 owner,
217 body: db.body(owner),
217 resolver, 218 resolver,
218 } 219 }
219 } 220 }
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index 6d9792391..c6802487a 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -130,10 +130,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
130 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, 130 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 },
131 Substs(sig_tys.into()), 131 Substs(sig_tys.into()),
132 ); 132 );
133 let closure_ty = Ty::apply_one( 133 let closure_ty =
134 TypeCtor::Closure { def: self.body.owner(), expr: tgt_expr }, 134 Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty);
135 sig_ty,
136 );
137 135
138 // Eagerly try to relate the closure type with the expected 136 // Eagerly try to relate the closure type with the expected
139 // type, otherwise we often won't have enough information to 137 // type, otherwise we often won't have enough information to
@@ -184,7 +182,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
184 } 182 }
185 Expr::Path(p) => { 183 Expr::Path(p) => {
186 // FIXME this could be more efficient... 184 // FIXME this could be more efficient...
187 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); 185 let resolver = expr::resolver_for_expr(self.db, self.owner, tgt_expr);
188 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) 186 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
189 } 187 }
190 Expr::Continue => Ty::simple(TypeCtor::Never), 188 Expr::Continue => Ty::simple(TypeCtor::Never),