aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/op.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-01 12:57:26 +0000
committerGitHub <[email protected]>2021-03-01 12:57:26 +0000
commitcda13d54613006c7985da0489878605300ba05b8 (patch)
tree81a8fc4b890192c41f00f7731929e781c3cb790a /crates/hir_ty/src/op.rs
parent1c7b2b8c0748c9548500d0dc08c8da1d1a36c81a (diff)
parent4b7fc693150f333cefe0e69d93271807f32741c4 (diff)
Merge #7823
7823: Being Ty::InferenceVar closer to chalk equivalent r=flodiebold a=Veykril Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/op.rs')
-rw-r--r--crates/hir_ty/src/op.rs15
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.
2use chalk_ir::TyVariableKind;
2use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; 3use hir_def::expr::{ArithOp, BinaryOp, CmpOp};
3 4
4use crate::{InferTy, Scalar, Ty}; 5use crate::{Scalar, Ty};
5 6
6pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { 7pub(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 }