aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/op.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/op.rs')
-rw-r--r--crates/ra_hir/src/ty/op.rs92
1 files changed, 24 insertions, 68 deletions
diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs
index 9ba868298..1b30a5b9b 100644
--- a/crates/ra_hir/src/ty/op.rs
+++ b/crates/ra_hir/src/ty/op.rs
@@ -1,37 +1,14 @@
1use super::{InferTy, Ty, TypeCtor}; 1use super::{InferTy, Ty, TypeCtor};
2use crate::{expr::BinaryOp, ty::ApplicationTy}; 2use crate::{
3 expr::{BinaryOp, CmpOp},
4 ty::ApplicationTy,
5};
3 6
4pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { 7pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
5 match op { 8 match op {
6 BinaryOp::BooleanOr 9 BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool),
7 | BinaryOp::BooleanAnd 10 BinaryOp::Assignment { .. } => Ty::unit(),
8 | BinaryOp::EqualityTest 11 BinaryOp::ArithOp(_) => match rhs_ty {
9 | BinaryOp::NegatedEqualityTest
10 | BinaryOp::LesserEqualTest
11 | BinaryOp::GreaterEqualTest
12 | BinaryOp::LesserTest
13 | BinaryOp::GreaterTest => Ty::simple(TypeCtor::Bool),
14 BinaryOp::Assignment
15 | BinaryOp::AddAssign
16 | BinaryOp::SubAssign
17 | BinaryOp::DivAssign
18 | BinaryOp::MulAssign
19 | BinaryOp::RemAssign
20 | BinaryOp::ShrAssign
21 | BinaryOp::ShlAssign
22 | BinaryOp::BitAndAssign
23 | BinaryOp::BitOrAssign
24 | BinaryOp::BitXorAssign => Ty::unit(),
25 BinaryOp::Addition
26 | BinaryOp::Subtraction
27 | BinaryOp::Multiplication
28 | BinaryOp::Division
29 | BinaryOp::Remainder
30 | BinaryOp::LeftShift
31 | BinaryOp::RightShift
32 | BinaryOp::BitwiseAnd
33 | BinaryOp::BitwiseOr
34 | BinaryOp::BitwiseXor => match rhs_ty {
35 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 12 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
36 TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, 13 TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty,
37 _ => Ty::Unknown, 14 _ => Ty::Unknown,
@@ -39,49 +16,29 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
39 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, 16 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty,
40 _ => Ty::Unknown, 17 _ => Ty::Unknown,
41 }, 18 },
42 BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown,
43 } 19 }
44} 20}
45 21
46pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { 22pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
47 match op { 23 match op {
48 BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::simple(TypeCtor::Bool), 24 BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool),
49 BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { 25 BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => {
50 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 26 match lhs_ty {
51 TypeCtor::Int(..) 27 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
52 | TypeCtor::Float(..) 28 TypeCtor::Int(..)
53 | TypeCtor::Str 29 | TypeCtor::Float(..)
54 | TypeCtor::Char 30 | TypeCtor::Str
55 | TypeCtor::Bool => lhs_ty, 31 | TypeCtor::Char
32 | TypeCtor::Bool => lhs_ty,
33 _ => Ty::Unknown,
34 },
35 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
56 _ => Ty::Unknown, 36 _ => Ty::Unknown,
57 }, 37 }
58 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, 38 }
59 _ => Ty::Unknown, 39 BinaryOp::CmpOp(CmpOp::Ord { .. })
60 }, 40 | BinaryOp::Assignment { op: Some(_) }
61 BinaryOp::LesserEqualTest 41 | BinaryOp::ArithOp(_) => match lhs_ty {
62 | BinaryOp::GreaterEqualTest
63 | BinaryOp::LesserTest
64 | BinaryOp::GreaterTest
65 | BinaryOp::AddAssign
66 | BinaryOp::SubAssign
67 | BinaryOp::DivAssign
68 | BinaryOp::MulAssign
69 | BinaryOp::RemAssign
70 | BinaryOp::ShrAssign
71 | BinaryOp::ShlAssign
72 | BinaryOp::BitAndAssign
73 | BinaryOp::BitOrAssign
74 | BinaryOp::BitXorAssign
75 | BinaryOp::Addition
76 | BinaryOp::Subtraction
77 | BinaryOp::Multiplication
78 | BinaryOp::Division
79 | BinaryOp::Remainder
80 | BinaryOp::LeftShift
81 | BinaryOp::RightShift
82 | BinaryOp::BitwiseAnd
83 | BinaryOp::BitwiseOr
84 | BinaryOp::BitwiseXor => match lhs_ty {
85 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 42 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
86 TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, 43 TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
87 _ => Ty::Unknown, 44 _ => Ty::Unknown,
@@ -89,6 +46,5 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
89 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, 46 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
90 _ => Ty::Unknown, 47 _ => Ty::Unknown,
91 }, 48 },
92 _ => Ty::Unknown,
93 } 49 }
94} 50}