aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/infer/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index e89cc7298..1fdb235a0 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -14,9 +14,7 @@ use hir_expand::name::Name;
14use ra_syntax::ast::RangeOp; 14use ra_syntax::ast::RangeOp;
15 15
16use crate::{ 16use crate::{
17 autoderef, 17 autoderef, method_resolution, op,
18 db::HirDatabase,
19 method_resolution, op,
20 traits::InEnvironment, 18 traits::InEnvironment,
21 utils::{generics, variant_data, Generics}, 19 utils::{generics, variant_data, Generics},
22 ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, 20 ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef,
@@ -25,7 +23,7 @@ use crate::{
25 23
26use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; 24use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
27 25
28impl<'a, D: HirDatabase> InferenceContext<'a, D> { 26impl<'a> InferenceContext<'a> {
29 pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { 27 pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
30 let ty = self.infer_expr_inner(tgt_expr, expected); 28 let ty = self.infer_expr_inner(tgt_expr, expected);
31 let could_unify = self.unify(&ty, &expected.ty); 29 let could_unify = self.unify(&ty, &expected.ty);
@@ -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 = resolver_for_expr(self.db, self.owner, tgt_expr); 185 let resolver = resolver_for_expr(self.db.upcast(), 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),
@@ -214,7 +212,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
214 212
215 let substs = ty.substs().unwrap_or_else(Substs::empty); 213 let substs = ty.substs().unwrap_or_else(Substs::empty);
216 let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); 214 let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default();
217 let variant_data = def_id.map(|it| variant_data(self.db, it)); 215 let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it));
218 for (field_idx, field) in fields.iter().enumerate() { 216 for (field_idx, field) in fields.iter().enumerate() {
219 let field_def = 217 let field_def =
220 variant_data.as_ref().and_then(|it| match it.field(&field.name) { 218 variant_data.as_ref().and_then(|it| match it.field(&field.name) {
@@ -579,7 +577,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
579 let receiver_ty = self.infer_expr(receiver, &Expectation::none()); 577 let receiver_ty = self.infer_expr(receiver, &Expectation::none());
580 let canonicalized_receiver = self.canonicalizer().canonicalize_ty(receiver_ty.clone()); 578 let canonicalized_receiver = self.canonicalizer().canonicalize_ty(receiver_ty.clone());
581 579
582 let traits_in_scope = self.resolver.traits_in_scope(self.db); 580 let traits_in_scope = self.resolver.traits_in_scope(self.db.upcast());
583 581
584 let resolved = self.resolver.krate().and_then(|krate| { 582 let resolved = self.resolver.krate().and_then(|krate| {
585 method_resolution::lookup_method( 583 method_resolution::lookup_method(
@@ -595,7 +593,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
595 Some((ty, func)) => { 593 Some((ty, func)) => {
596 let ty = canonicalized_receiver.decanonicalize_ty(ty); 594 let ty = canonicalized_receiver.decanonicalize_ty(ty);
597 self.write_method_resolution(tgt_expr, func); 595 self.write_method_resolution(tgt_expr, func);
598 (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) 596 (ty, self.db.value_ty(func.into()), Some(generics(self.db.upcast(), func.into())))
599 } 597 }
600 None => (receiver_ty, Binders::new(0, Ty::Unknown), None), 598 None => (receiver_ty, Binders::new(0, Ty::Unknown), None),
601 }; 599 };
@@ -703,10 +701,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
703 // add obligation for trait implementation, if this is a trait method 701 // add obligation for trait implementation, if this is a trait method
704 match def { 702 match def {
705 CallableDef::FunctionId(f) => { 703 CallableDef::FunctionId(f) => {
706 if let AssocContainerId::TraitId(trait_) = f.lookup(self.db).container { 704 if let AssocContainerId::TraitId(trait_) =
705 f.lookup(self.db.upcast()).container
706 {
707 // construct a TraitDef 707 // construct a TraitDef
708 let substs = 708 let substs = a_ty
709 a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); 709 .parameters
710 .prefix(generics(self.db.upcast(), trait_.into()).len());
710 self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); 711 self.obligations.push(Obligation::Trait(TraitRef { trait_, substs }));
711 } 712 }
712 } 713 }