diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/op.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 29 |
2 files changed, 31 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(..) |
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 3820175f6..322838f02 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -1787,3 +1787,32 @@ fn main() { | |||
1787 | "### | 1787 | "### |
1788 | ) | 1788 | ) |
1789 | } | 1789 | } |
1790 | |||
1791 | #[test] | ||
1792 | fn infer_generic_from_later_assignment() { | ||
1793 | assert_snapshot!( | ||
1794 | infer(r#" | ||
1795 | enum Option<T> { Some(T), None } | ||
1796 | use Option::*; | ||
1797 | |||
1798 | fn test() { | ||
1799 | let mut end = None; | ||
1800 | loop { | ||
1801 | end = Some(true); | ||
1802 | } | ||
1803 | } | ||
1804 | "#), | ||
1805 | @r###" | ||
1806 | 60..130 '{ ... } }': () | ||
1807 | 70..77 'mut end': Option<bool> | ||
1808 | 80..84 'None': Option<bool> | ||
1809 | 90..128 'loop {... }': ! | ||
1810 | 95..128 '{ ... }': () | ||
1811 | 105..108 'end': Option<bool> | ||
1812 | 105..121 'end = ...(true)': () | ||
1813 | 111..115 'Some': Some<bool>(bool) -> Option<bool> | ||
1814 | 111..121 'Some(true)': Option<bool> | ||
1815 | 116..120 'true': bool | ||
1816 | "### | ||
1817 | ); | ||
1818 | } | ||