diff options
Diffstat (limited to 'crates/hir_ty/src/op.rs')
-rw-r--r-- | crates/hir_ty/src/op.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/crates/hir_ty/src/op.rs b/crates/hir_ty/src/op.rs index 1c01a67ad..bb9b8bbfc 100644 --- a/crates/hir_ty/src/op.rs +++ b/crates/hir_ty/src/op.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | //! Helper functions for binary operator type inference. | 1 | //! Helper functions for binary operator type inference. |
2 | use chalk_ir::TyVariableKind; | ||
2 | use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; | 3 | use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; |
3 | 4 | ||
4 | use crate::{InferTy, Scalar, Ty}; | 5 | use crate::{Scalar, Ty}; |
5 | 6 | ||
6 | pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { | 7 | pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { |
7 | match op { | 8 | match op { |
@@ -11,14 +12,16 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { | |||
11 | Ty::Scalar(Scalar::Int(_)) | 12 | Ty::Scalar(Scalar::Int(_)) |
12 | | Ty::Scalar(Scalar::Uint(_)) | 13 | | Ty::Scalar(Scalar::Uint(_)) |
13 | | Ty::Scalar(Scalar::Float(_)) => lhs_ty, | 14 | | Ty::Scalar(Scalar::Float(_)) => lhs_ty, |
14 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 15 | Ty::InferenceVar(_, TyVariableKind::Integer) |
16 | | Ty::InferenceVar(_, TyVariableKind::Float) => lhs_ty, | ||
15 | _ => Ty::Unknown, | 17 | _ => Ty::Unknown, |
16 | }, | 18 | }, |
17 | BinaryOp::ArithOp(_) => match rhs_ty { | 19 | BinaryOp::ArithOp(_) => match rhs_ty { |
18 | Ty::Scalar(Scalar::Int(_)) | 20 | Ty::Scalar(Scalar::Int(_)) |
19 | | Ty::Scalar(Scalar::Uint(_)) | 21 | | Ty::Scalar(Scalar::Uint(_)) |
20 | | Ty::Scalar(Scalar::Float(_)) => rhs_ty, | 22 | | Ty::Scalar(Scalar::Float(_)) => rhs_ty, |
21 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, | 23 | Ty::InferenceVar(_, TyVariableKind::Integer) |
24 | | Ty::InferenceVar(_, TyVariableKind::Float) => rhs_ty, | ||
22 | _ => Ty::Unknown, | 25 | _ => Ty::Unknown, |
23 | }, | 26 | }, |
24 | } | 27 | } |
@@ -30,7 +33,8 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | |||
30 | BinaryOp::Assignment { op: None } => lhs_ty, | 33 | BinaryOp::Assignment { op: None } => lhs_ty, |
31 | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { | 34 | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { |
32 | Ty::Scalar(_) | Ty::Str => lhs_ty, | 35 | Ty::Scalar(_) | Ty::Str => lhs_ty, |
33 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 36 | Ty::InferenceVar(_, TyVariableKind::Integer) |
37 | | Ty::InferenceVar(_, TyVariableKind::Float) => lhs_ty, | ||
34 | _ => Ty::Unknown, | 38 | _ => Ty::Unknown, |
35 | }, | 39 | }, |
36 | BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, | 40 | BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, |
@@ -40,7 +44,8 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | |||
40 | Ty::Scalar(Scalar::Int(_)) | 44 | Ty::Scalar(Scalar::Int(_)) |
41 | | Ty::Scalar(Scalar::Uint(_)) | 45 | | Ty::Scalar(Scalar::Uint(_)) |
42 | | Ty::Scalar(Scalar::Float(_)) => lhs_ty, | 46 | | Ty::Scalar(Scalar::Float(_)) => lhs_ty, |
43 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 47 | Ty::InferenceVar(_, TyVariableKind::Integer) |
48 | | Ty::InferenceVar(_, TyVariableKind::Float) => lhs_ty, | ||
44 | _ => Ty::Unknown, | 49 | _ => Ty::Unknown, |
45 | }, | 50 | }, |
46 | } | 51 | } |