diff options
-rw-r--r-- | crates/ra_hir/src/expr.rs | 30 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/op.rs | 32 |
2 files changed, 36 insertions, 26 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index ea3fa4417..5430a0c9f 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -273,12 +273,14 @@ pub enum LogicOp { | |||
273 | 273 | ||
274 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 274 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
275 | pub enum CmpOp { | 275 | pub enum CmpOp { |
276 | Equal, | 276 | Eq { negated: bool }, |
277 | NotEqual, | 277 | Ord { ordering: Ordering, strict: bool }, |
278 | } | ||
279 | |||
280 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
281 | pub enum Ordering { | ||
278 | Less, | 282 | Less, |
279 | LessOrEqual, | ||
280 | Greater, | 283 | Greater, |
281 | GreaterOrEqual, | ||
282 | } | 284 | } |
283 | 285 | ||
284 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 286 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
@@ -1080,12 +1082,20 @@ impl From<ast::BinOp> for BinaryOp { | |||
1080 | match ast_op { | 1082 | match ast_op { |
1081 | ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or), | 1083 | ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or), |
1082 | ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And), | 1084 | ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And), |
1083 | ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Equal), | 1085 | ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: false }), |
1084 | ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::NotEqual), | 1086 | ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: true }), |
1085 | ast::BinOp::LesserEqualTest => BinaryOp::CmpOp(CmpOp::LessOrEqual), | 1087 | ast::BinOp::LesserEqualTest => { |
1086 | ast::BinOp::GreaterEqualTest => BinaryOp::CmpOp(CmpOp::GreaterOrEqual), | 1088 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: false }) |
1087 | ast::BinOp::LesserTest => BinaryOp::CmpOp(CmpOp::Less), | 1089 | } |
1088 | ast::BinOp::GreaterTest => BinaryOp::CmpOp(CmpOp::Greater), | 1090 | ast::BinOp::GreaterEqualTest => { |
1091 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: false }) | ||
1092 | } | ||
1093 | ast::BinOp::LesserTest => { | ||
1094 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: true }) | ||
1095 | } | ||
1096 | ast::BinOp::GreaterTest => { | ||
1097 | BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: true }) | ||
1098 | } | ||
1089 | ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add), | 1099 | ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add), |
1090 | ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul), | 1100 | ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul), |
1091 | ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub), | 1101 | ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub), |
diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs index 1d089f1b0..1b30a5b9b 100644 --- a/crates/ra_hir/src/ty/op.rs +++ b/crates/ra_hir/src/ty/op.rs | |||
@@ -22,29 +22,29 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { | |||
22 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | 22 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { |
23 | match op { | 23 | match op { |
24 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), | 24 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), |
25 | BinaryOp::Assignment { op: None } | 25 | BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => { |
26 | | BinaryOp::CmpOp(CmpOp::Equal) | ||
27 | | BinaryOp::CmpOp(CmpOp::NotEqual) => match lhs_ty { | ||
28 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | ||
29 | TypeCtor::Int(..) | ||
30 | | TypeCtor::Float(..) | ||
31 | | TypeCtor::Str | ||
32 | | TypeCtor::Char | ||
33 | | TypeCtor::Bool => lhs_ty, | ||
34 | _ => Ty::Unknown, | ||
35 | }, | ||
36 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | ||
37 | _ => Ty::Unknown, | ||
38 | }, | ||
39 | BinaryOp::CmpOp(_) | BinaryOp::Assignment { op: Some(_) } | BinaryOp::ArithOp(_) => { | ||
40 | match lhs_ty { | 26 | match lhs_ty { |
41 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 27 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
42 | TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, | 28 | TypeCtor::Int(..) |
29 | | TypeCtor::Float(..) | ||
30 | | TypeCtor::Str | ||
31 | | TypeCtor::Char | ||
32 | | TypeCtor::Bool => lhs_ty, | ||
43 | _ => Ty::Unknown, | 33 | _ => Ty::Unknown, |
44 | }, | 34 | }, |
45 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 35 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, |
46 | _ => Ty::Unknown, | 36 | _ => Ty::Unknown, |
47 | } | 37 | } |
48 | } | 38 | } |
39 | BinaryOp::CmpOp(CmpOp::Ord { .. }) | ||
40 | | BinaryOp::Assignment { op: Some(_) } | ||
41 | | BinaryOp::ArithOp(_) => match lhs_ty { | ||
42 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | ||
43 | TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, | ||
44 | _ => Ty::Unknown, | ||
45 | }, | ||
46 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | ||
47 | _ => Ty::Unknown, | ||
48 | }, | ||
49 | } | 49 | } |
50 | } | 50 | } |