aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/op.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/op.rs')
-rw-r--r--crates/ra_hir_ty/src/op.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/crates/ra_hir_ty/src/op.rs b/crates/ra_hir_ty/src/op.rs
index 09c47a76d..ae253ca04 100644
--- a/crates/ra_hir_ty/src/op.rs
+++ b/crates/ra_hir_ty/src/op.rs
@@ -1,13 +1,21 @@
1//! FIXME: write short doc here 1//! Helper functions for binary operator type inference.
2use hir_def::expr::{BinaryOp, CmpOp}; 2use hir_def::expr::{ArithOp, BinaryOp, CmpOp};
3 3
4use super::{InferTy, Ty, TypeCtor}; 4use super::{InferTy, Ty, TypeCtor};
5use crate::ApplicationTy; 5use crate::ApplicationTy;
6 6
7pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { 7pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
8 match op { 8 match op {
9 BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool), 9 BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool),
10 BinaryOp::Assignment { .. } => Ty::unit(), 10 BinaryOp::Assignment { .. } => Ty::unit(),
11 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => match lhs_ty {
12 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
13 TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
14 _ => Ty::Unknown,
15 },
16 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
17 _ => Ty::Unknown,
18 },
11 BinaryOp::ArithOp(_) => match rhs_ty { 19 BinaryOp::ArithOp(_) => match rhs_ty {
12 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 20 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
13 TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, 21 TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
@@ -36,6 +44,7 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
36 _ => Ty::Unknown, 44 _ => Ty::Unknown,
37 } 45 }
38 } 46 }
47 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown,
39 BinaryOp::CmpOp(CmpOp::Ord { .. }) 48 BinaryOp::CmpOp(CmpOp::Ord { .. })
40 | BinaryOp::Assignment { op: Some(_) } 49 | BinaryOp::Assignment { op: Some(_) }
41 | BinaryOp::ArithOp(_) => match lhs_ty { 50 | BinaryOp::ArithOp(_) => match lhs_ty {