From 85d44cad45761a55741ff406e23f2e40b0f24b88 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Sun, 10 May 2020 16:20:13 +0200 Subject: infer: Make expected rhs type for plain assign the lhs type This fixes an issue where the following code sample would fail to infer the type contained in the option: ```rust fn main() { let mut end = None; // TODO: Fix inference for this in RA loop { end = Some(true); } } ``` --- crates/ra_hir_ty/src/op.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/op.rs') diff --git a/crates/ra_hir_ty/src/op.rs b/crates/ra_hir_ty/src/op.rs index 54e2bd05a..0870874fc 100644 --- a/crates/ra_hir_ty/src/op.rs +++ b/crates/ra_hir_ty/src/op.rs @@ -30,7 +30,8 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { match op { BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), - BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { + BinaryOp::Assignment { op: None } => lhs_ty, + BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { TypeCtor::Int(..) | TypeCtor::Float(..) -- cgit v1.2.3