diff options
author | TomasKralCZ <[email protected]> | 2020-01-19 16:51:03 +0000 |
---|---|---|
committer | TomasKralCZ <[email protected]> | 2020-01-19 16:51:03 +0000 |
commit | 514df15d9e32e057ba23dda0d4f5c07e82e7ed23 (patch) | |
tree | 41e93f63182bae10a7325fc50220f67df79aaece /crates/ra_hir_ty/src/op.rs | |
parent | c3b9a19eb72ae9542272ae7a22ac3fb57c75daca (diff) | |
parent | 3a7724e44181ccd5c248589538bd82458b5a9407 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_hir_ty/src/op.rs')
-rw-r--r-- | crates/ra_hir_ty/src/op.rs | 15 |
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. |
2 | use hir_def::expr::{BinaryOp, CmpOp}; | 2 | use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; |
3 | 3 | ||
4 | use super::{InferTy, Ty, TypeCtor}; | 4 | use super::{InferTy, Ty, TypeCtor}; |
5 | use crate::ApplicationTy; | 5 | use crate::ApplicationTy; |
6 | 6 | ||
7 | pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { | 7 | pub(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 { |