diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 23:05:28 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 23:05:28 +0000 |
commit | 68d320a680b5df802b2c3e7dad5d890e3309ed60 (patch) | |
tree | f38fafe9cbc4efea5574afa6c40a0fea403bf34c /crates/ra_hir/src/ty.rs | |
parent | ab46f8abf195a78c018d8b23896eb920d16b028b (diff) | |
parent | a2b6d3da30020421c97100d7c8699a3b4f8cd6fb (diff) |
Merge #544
544: Implement rudimentary type inference for unary operators r=marcusklaas a=marcusklaas
Co-authored-by: Marcus Klaas de Vries <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index dbbbce795..85d4dc05c 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -1051,7 +1051,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1051 | Expr::UnaryOp { expr, op } => { | 1051 | Expr::UnaryOp { expr, op } => { |
1052 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); | 1052 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); |
1053 | match op { | 1053 | match op { |
1054 | Some(UnaryOp::Deref) => { | 1054 | UnaryOp::Deref => { |
1055 | if let Some(derefed_ty) = inner_ty.builtin_deref() { | 1055 | if let Some(derefed_ty) = inner_ty.builtin_deref() { |
1056 | derefed_ty | 1056 | derefed_ty |
1057 | } else { | 1057 | } else { |
@@ -1059,7 +1059,20 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1059 | Ty::Unknown | 1059 | Ty::Unknown |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | _ => Ty::Unknown, | 1062 | UnaryOp::Neg => { |
1063 | match inner_ty { | ||
1064 | Ty::Int(primitive::UncertainIntTy::Unknown) | ||
1065 | | Ty::Int(primitive::UncertainIntTy::Signed(..)) | ||
1066 | | Ty::Infer(InferTy::IntVar(..)) | ||
1067 | | Ty::Infer(InferTy::FloatVar(..)) | ||
1068 | | Ty::Float(..) => inner_ty, | ||
1069 | // TODO: resolve ops::Neg trait | ||
1070 | _ => Ty::Unknown, | ||
1071 | } | ||
1072 | } | ||
1073 | UnaryOp::Not if inner_ty == Ty::Bool => Ty::Bool, | ||
1074 | // TODO: resolve ops::Not trait for inner_ty | ||
1075 | UnaryOp::Not => Ty::Unknown, | ||
1063 | } | 1076 | } |
1064 | } | 1077 | } |
1065 | Expr::BinaryOp { lhs, rhs, op } => match op { | 1078 | Expr::BinaryOp { lhs, rhs, op } => match op { |