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.rs36
1 files changed, 12 insertions, 24 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 39d8bc0ca..9d5f75625 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -35,8 +35,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, 35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() },
36 ); 36 );
37 } 37 }
38 let ty = self.resolve_ty_as_possible(ty); 38 self.resolve_ty_as_possible(ty)
39 ty
40 } 39 }
41 40
42 /// Infer type of expression with possibly implicit coerce to the expected type. 41 /// Infer type of expression with possibly implicit coerce to the expected type.
@@ -127,10 +126,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
127 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, 126 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 },
128 Substs(sig_tys.into()), 127 Substs(sig_tys.into()),
129 ); 128 );
130 let closure_ty = Ty::apply_one( 129 let closure_ty =
131 TypeCtor::Closure { def: self.owner.into(), expr: tgt_expr }, 130 Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty);
132 sig_ty,
133 );
134 131
135 // Eagerly try to relate the closure type with the expected 132 // Eagerly try to relate the closure type with the expected
136 // type, otherwise we often won't have enough information to 133 // type, otherwise we often won't have enough information to
@@ -157,15 +154,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
157 }; 154 };
158 self.register_obligations_for_call(&callee_ty); 155 self.register_obligations_for_call(&callee_ty);
159 self.check_call_arguments(args, &param_tys); 156 self.check_call_arguments(args, &param_tys);
160 let ret_ty = self.normalize_associated_types_in(ret_ty); 157 self.normalize_associated_types_in(ret_ty)
161 ret_ty
162 } 158 }
163 Expr::MethodCall { receiver, args, method_name, generic_args } => self 159 Expr::MethodCall { receiver, args, method_name, generic_args } => self
164 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), 160 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()),
165 Expr::Match { expr, arms } => { 161 Expr::Match { expr, arms } => {
166 let input_ty = self.infer_expr(*expr, &Expectation::none()); 162 let input_ty = self.infer_expr(*expr, &Expectation::none());
167 163
168 let mut result_ty = if arms.len() == 0 { 164 let mut result_ty = if arms.is_empty() {
169 Ty::simple(TypeCtor::Never) 165 Ty::simple(TypeCtor::Never)
170 } else { 166 } else {
171 self.table.new_type_var() 167 self.table.new_type_var()
@@ -188,7 +184,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
188 } 184 }
189 Expr::Path(p) => { 185 Expr::Path(p) => {
190 // FIXME this could be more efficient... 186 // FIXME this could be more efficient...
191 let resolver = resolver_for_expr(self.db, self.owner.into(), tgt_expr); 187 let resolver = resolver_for_expr(self.db, self.owner, tgt_expr);
192 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) 188 self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
193 } 189 }
194 Expr::Continue => Ty::simple(TypeCtor::Never), 190 Expr::Continue => Ty::simple(TypeCtor::Never),
@@ -217,8 +213,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
217 self.unify(&ty, &expected.ty); 213 self.unify(&ty, &expected.ty);
218 214
219 let substs = ty.substs().unwrap_or_else(Substs::empty); 215 let substs = ty.substs().unwrap_or_else(Substs::empty);
220 let field_types = 216 let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default();
221 def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default();
222 let variant_data = def_id.map(|it| variant_data(self.db, it)); 217 let variant_data = def_id.map(|it| variant_data(self.db, it));
223 for (field_idx, field) in fields.iter().enumerate() { 218 for (field_idx, field) in fields.iter().enumerate() {
224 let field_def = 219 let field_def =
@@ -264,7 +259,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
264 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), 259 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
265 TypeCtor::Adt(AdtId::StructId(s)) => { 260 TypeCtor::Adt(AdtId::StructId(s)) => {
266 self.db.struct_data(s).variant_data.field(name).map(|local_id| { 261 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
267 let field = StructFieldId { parent: s.into(), local_id }.into(); 262 let field = StructFieldId { parent: s.into(), local_id };
268 self.write_field_resolution(tgt_expr, field); 263 self.write_field_resolution(tgt_expr, field);
269 self.db.field_types(s.into())[field.local_id] 264 self.db.field_types(s.into())[field.local_id]
270 .clone() 265 .clone()
@@ -283,14 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
283 } 278 }
284 Expr::Await { expr } => { 279 Expr::Await { expr } => {
285 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 280 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
286 let ty = 281 self.resolve_associated_type(inner_ty, self.resolve_future_future_output())
287 self.resolve_associated_type(inner_ty, self.resolve_future_future_output());
288 ty
289 } 282 }
290 Expr::Try { expr } => { 283 Expr::Try { expr } => {
291 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 284 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
292 let ty = self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok()); 285 self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok())
293 ty
294 } 286 }
295 Expr::Cast { expr, type_ref } => { 287 Expr::Cast { expr, type_ref } => {
296 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 288 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
@@ -614,8 +606,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
614 self.unify(&expected_receiver_ty, &actual_receiver_ty); 606 self.unify(&expected_receiver_ty, &actual_receiver_ty);
615 607
616 self.check_call_arguments(args, &param_tys); 608 self.check_call_arguments(args, &param_tys);
617 let ret_ty = self.normalize_associated_types_in(ret_ty); 609 self.normalize_associated_types_in(ret_ty)
618 ret_ty
619 } 610 }
620 611
621 fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { 612 fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) {
@@ -700,10 +691,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
700 // construct a TraitDef 691 // construct a TraitDef
701 let substs = 692 let substs =
702 a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); 693 a_ty.parameters.prefix(generics(self.db, trait_.into()).len());
703 self.obligations.push(Obligation::Trait(TraitRef { 694 self.obligations.push(Obligation::Trait(TraitRef { trait_, substs }));
704 trait_: trait_.into(),
705 substs,
706 }));
707 } 695 }
708 } 696 }
709 CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} 697 CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {}