aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/simple.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-10 15:48:04 +0100
committerGitHub <[email protected]>2020-05-10 15:48:04 +0100
commit225f353aa26329260b8c7f69305f616a9edaad70 (patch)
tree3557b041edfbab6a1c85a1701d7d322b829a43a6 /crates/ra_hir_ty/src/tests/simple.rs
parent4578154b608fa075595103d0c933da60d55b25c8 (diff)
parent85d44cad45761a55741ff406e23f2e40b0f24b88 (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/tests/simple.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs29
1 files changed, 29 insertions, 0 deletions
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]
1792fn infer_generic_from_later_assignment() {
1793 assert_snapshot!(
1794 infer(r#"
1795enum Option<T> { Some(T), None }
1796use Option::*;
1797
1798fn 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}