diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-10 15:48:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-10 15:48:04 +0100 |
commit | 225f353aa26329260b8c7f69305f616a9edaad70 (patch) | |
tree | 3557b041edfbab6a1c85a1701d7d322b829a43a6 /crates/ra_hir_ty/src/op.rs | |
parent | 4578154b608fa075595103d0c933da60d55b25c8 (diff) | |
parent | 85d44cad45761a55741ff406e23f2e40b0f24b88 (diff) |
Merge #4412
4412: infer: Make expected rhs type for plain assign the lhs type r=flodiebold a=kiljacken
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; // Was Option<{unknown}>, is now Option<bool>
loop {
end = Some(true);
}
}
```
Co-authored-by: Emil Lauridsen <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/op.rs')
-rw-r--r-- | crates/ra_hir_ty/src/op.rs | 3 |
1 files changed, 2 insertions, 1 deletions
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 { | |||
30 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | 30 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { |
31 | match op { | 31 | match op { |
32 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), | 32 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), |
33 | BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { | 33 | BinaryOp::Assignment { op: None } => lhs_ty, |
34 | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { | ||
34 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 35 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
35 | TypeCtor::Int(..) | 36 | TypeCtor::Int(..) |
36 | | TypeCtor::Float(..) | 37 | | TypeCtor::Float(..) |