diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/coerce.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/unify.rs | 5 |
3 files changed, 10 insertions, 18 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 4a0eabdfc..fb6a51b12 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -26,7 +26,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
26 | /// Note that it is only possible that one type are coerced to another. | 26 | /// Note that it is only possible that one type are coerced to another. |
27 | /// Coercing both types to another least upper bound type is not possible in rustc, | 27 | /// Coercing both types to another least upper bound type is not possible in rustc, |
28 | /// which will simply result in "incompatible types" error. | 28 | /// which will simply result in "incompatible types" error. |
29 | pub(super) fn coerce_merge_branch<'t>(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { | 29 | pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { |
30 | if self.coerce(ty1, ty2) { | 30 | if self.coerce(ty1, ty2) { |
31 | ty2.clone() | 31 | ty2.clone() |
32 | } else if self.coerce(ty2, ty1) { | 32 | } else if self.coerce(ty2, ty1) { |
@@ -252,15 +252,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
252 | let unsize_generic_index = { | 252 | let unsize_generic_index = { |
253 | let mut index = None; | 253 | let mut index = None; |
254 | let mut multiple_param = false; | 254 | let mut multiple_param = false; |
255 | field_tys[last_field_id].value.walk(&mut |ty| match ty { | 255 | field_tys[last_field_id].value.walk(&mut |ty| { |
256 | &Ty::Bound(idx) => { | 256 | if let &Ty::Bound(idx) = ty { |
257 | if index.is_none() { | 257 | if index.is_none() { |
258 | index = Some(idx); | 258 | index = Some(idx); |
259 | } else if Some(idx) != index { | 259 | } else if Some(idx) != index { |
260 | multiple_param = true; | 260 | multiple_param = true; |
261 | } | 261 | } |
262 | } | 262 | } |
263 | _ => {} | ||
264 | }); | 263 | }); |
265 | 264 | ||
266 | if multiple_param { | 265 | if multiple_param { |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 0af94ae32..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. |
@@ -155,8 +154,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
155 | }; | 154 | }; |
156 | self.register_obligations_for_call(&callee_ty); | 155 | self.register_obligations_for_call(&callee_ty); |
157 | self.check_call_arguments(args, ¶m_tys); | 156 | self.check_call_arguments(args, ¶m_tys); |
158 | let ret_ty = self.normalize_associated_types_in(ret_ty); | 157 | self.normalize_associated_types_in(ret_ty) |
159 | ret_ty | ||
160 | } | 158 | } |
161 | Expr::MethodCall { receiver, args, method_name, generic_args } => self | 159 | Expr::MethodCall { receiver, args, method_name, generic_args } => self |
162 | .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()), |
@@ -280,14 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
280 | } | 278 | } |
281 | Expr::Await { expr } => { | 279 | Expr::Await { expr } => { |
282 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 280 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
283 | let ty = | 281 | self.resolve_associated_type(inner_ty, self.resolve_future_future_output()) |
284 | self.resolve_associated_type(inner_ty, self.resolve_future_future_output()); | ||
285 | ty | ||
286 | } | 282 | } |
287 | Expr::Try { expr } => { | 283 | Expr::Try { expr } => { |
288 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 284 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
289 | 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()) |
290 | ty | ||
291 | } | 286 | } |
292 | Expr::Cast { expr, type_ref } => { | 287 | Expr::Cast { expr, type_ref } => { |
293 | let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 288 | let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
@@ -611,8 +606,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
611 | self.unify(&expected_receiver_ty, &actual_receiver_ty); | 606 | self.unify(&expected_receiver_ty, &actual_receiver_ty); |
612 | 607 | ||
613 | self.check_call_arguments(args, ¶m_tys); | 608 | self.check_call_arguments(args, ¶m_tys); |
614 | let ret_ty = self.normalize_associated_types_in(ret_ty); | 609 | self.normalize_associated_types_in(ret_ty) |
615 | ret_ty | ||
616 | } | 610 | } |
617 | 611 | ||
618 | fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { | 612 | fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { |
diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index 1dc842f40..9c7996572 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs | |||
@@ -140,13 +140,12 @@ where | |||
140 | impl<T> Canonicalized<T> { | 140 | impl<T> Canonicalized<T> { |
141 | pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { | 141 | pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { |
142 | ty.walk_mut_binders( | 142 | ty.walk_mut_binders( |
143 | &mut |ty, binders| match ty { | 143 | &mut |ty, binders| { |
144 | &mut Ty::Bound(idx) => { | 144 | if let &mut Ty::Bound(idx) = ty { |
145 | if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { | 145 | if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { |
146 | *ty = Ty::Infer(self.free_vars[idx as usize - binders]); | 146 | *ty = Ty::Infer(self.free_vars[idx as usize - binders]); |
147 | } | 147 | } |
148 | } | 148 | } |
149 | _ => {} | ||
150 | }, | 149 | }, |
151 | 0, | 150 | 0, |
152 | ); | 151 | ); |