From b58dfd24f1bf1f30128fa9a78368b4d430e10e97 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 11:27:28 +0200 Subject: Add smoke test for decorated blocks --- crates/ra_hir_ty/src/tests/simple.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 56abc65b8..3d3088965 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1755,3 +1755,35 @@ fn main() { "### ); } + +#[test] +fn effects_smoke_test() { + assert_snapshot!( + infer(r#" +fn main() { + let x = unsafe { 92 }; + let y = async { async { () }.await }; + let z = try { () }; + let t = 'a: { 92 }; +} +"#), + @r###" + 11..131 '{ ...2 }; }': () + 21..22 'x': i32 + 32..38 '{ 92 }': i32 + 34..36 '92': i32 + 48..49 'y': {unknown} + 58..80 '{ asyn...wait }': {unknown} + 60..78 'async ....await': {unknown} + 66..72 '{ () }': () + 68..70 '()': () + 90..91 'z': {unknown} + 94..104 'try { () }': {unknown} + 98..104 '{ () }': () + 100..102 '()': () + 114..115 't': i32 + 122..128 '{ 92 }': i32 + 124..126 '92': i32 + "### + ) +} -- cgit v1.2.3 From f5177f91ae61e1d812efd6b55a1ec7ab07c7c7e1 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 8 May 2020 15:17:35 +0200 Subject: Fix type of byte literals They're `&[u8; N]`, not `&[u8]` (see #4374). --- crates/ra_hir_ty/src/tests/simple.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 3d3088965..e17a17900 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -414,7 +414,7 @@ fn test() { 27..31 '5f32': f32 37..41 '5f64': f64 47..54 '"hello"': &str - 60..68 'b"bytes"': &[u8] + 60..68 'b"bytes"': &[u8; _] 74..77 ''c'': char 83..87 'b'b'': u8 93..97 '3.14': f64 @@ -422,7 +422,7 @@ fn test() { 113..118 'false': bool 124..128 'true': bool 134..202 'r#" ... "#': &str - 208..218 'br#"yolo"#': &[u8] + 208..218 'br#"yolo"#': &[u8; _] "### ); } -- cgit v1.2.3 From fe7bf993aa8d64668707e348f2ea69918cfda9a4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 8 May 2020 17:36:11 +0200 Subject: Implement better handling of divergence Divergence here means that for some reason, the end of a block will not be reached. We tried to model this just using the never type, but that doesn't work fully (e.g. in `let x = { loop {}; "foo" };` x should still have type `&str`); so this introduces a `diverges` flag that the type checker keeps track of, like rustc does. --- crates/ra_hir_ty/src/tests/simple.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index e17a17900..3820175f6 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -179,7 +179,7 @@ fn test(a: u32, b: isize, c: !, d: &str) { 17..18 'b': isize 27..28 'c': ! 33..34 'd': &str - 42..121 '{ ...f32; }': ! + 42..121 '{ ...f32; }': () 48..49 'a': u32 55..56 'b': isize 62..63 'c': ! @@ -935,7 +935,7 @@ fn foo() { 29..33 'true': bool 34..51 '{ ... }': i32 44..45 '1': i32 - 57..80 '{ ... }': ! + 57..80 '{ ... }': i32 67..73 'return': ! 90..93 '_x2': i32 96..149 'if tru... }': i32 @@ -951,7 +951,7 @@ fn foo() { 186..190 'true': bool 194..195 '3': i32 205..206 '_': bool - 210..241 '{ ... }': ! + 210..241 '{ ... }': i32 224..230 'return': ! 257..260 '_x4': i32 263..320 'match ... }': i32 @@ -1687,7 +1687,7 @@ fn foo() -> u32 { 17..59 '{ ...; }; }': () 27..28 'x': || -> usize 31..56 '|| -> ...n 1; }': || -> usize - 43..56 '{ return 1; }': ! + 43..56 '{ return 1; }': usize 45..53 'return 1': ! 52..53 '1': usize "### @@ -1706,7 +1706,7 @@ fn foo() -> u32 { 17..48 '{ ...; }; }': () 27..28 'x': || -> () 31..45 '|| { return; }': || -> () - 34..45 '{ return; }': ! + 34..45 '{ return; }': () 36..42 'return': ! "### ); -- cgit v1.2.3 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/tests/simple.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') 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() { "### ) } + +#[test] +fn infer_generic_from_later_assignment() { + assert_snapshot!( + infer(r#" +enum Option { Some(T), None } +use Option::*; + +fn test() { + let mut end = None; + loop { + end = Some(true); + } +} +"#), + @r###" + 60..130 '{ ... } }': () + 70..77 'mut end': Option + 80..84 'None': Option + 90..128 'loop {... }': ! + 95..128 '{ ... }': () + 105..108 'end': Option + 105..121 'end = ...(true)': () + 111..115 'Some': Some(bool) -> Option + 111..121 'Some(true)': Option + 116..120 'true': bool + "### + ); +} -- cgit v1.2.3 From 3f42b2e837c4672a0fbe953e14ae2fd3fe6fc3b6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 15 May 2020 17:15:40 +0200 Subject: Handle `Self` in values and patterns I.e. - `Self(x)` or `Self` in tuple/unit struct impls - `Self::Variant(x)` or `Self::Variant` in enum impls - the same in patterns Fixes #4454. --- crates/ra_hir_ty/src/tests/simple.rs | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 322838f02..72122c070 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -575,6 +575,50 @@ impl S { ); } +#[test] +fn infer_self_as_path() { + assert_snapshot!( + infer(r#" +struct S1; +struct S2(isize); +enum E { + V1, + V2(u32), +} + +impl S1 { + fn test() { + Self; + } +} +impl S2 { + fn test() { + Self(1); + } +} +impl E { + fn test() { + Self::V1; + Self::V2(1); + } +} +"#), + @r###" + 87..108 '{ ... }': () + 97..101 'Self': S1 + 135..159 '{ ... }': () + 145..149 'Self': S2(isize) -> S2 + 145..152 'Self(1)': S2 + 150..151 '1': isize + 185..231 '{ ... }': () + 195..203 'Self::V1': E + 213..221 'Self::V2': V2(u32) -> E + 213..224 'Self::V2(1)': E + 222..223 '1': u32 + "### + ); +} + #[test] fn infer_binary_op() { assert_snapshot!( -- cgit v1.2.3 From da09f967469127576d9a87a7c143f754777a4f6b Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Tue, 19 May 2020 21:49:45 +0200 Subject: loop return value inference: add tests --- crates/ra_hir_ty/src/tests/simple.rs | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'crates/ra_hir_ty/src/tests/simple.rs') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 72122c070..fd2208af2 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1860,3 +1860,66 @@ fn test() { "### ); } + +#[test] +fn infer_loop_break_with_val() { + assert_snapshot!( + infer(r#" +enum Option { Some(T), None } +use Option::*; + +fn test() { + let x = loop { + if false { + break None; + } + + break Some(true); + }; +} +"#), + @r###" + 60..169 '{ ... }; }': () + 70..71 'x': Option + 74..166 'loop {... }': Option + 79..166 '{ ... }': () + 89..133 'if fal... }': () + 92..97 'false': bool + 98..133 '{ ... }': () + 112..122 'break None': ! + 118..122 'None': Option + 143..159 'break ...(true)': ! + 149..153 'Some': Some(bool) -> Option + 149..159 'Some(true)': Option + 154..158 'true': bool + "### + ); +} + +#[test] +fn infer_loop_break_without_val() { + assert_snapshot!( + infer(r#" +enum Option { Some(T), None } +use Option::*; + +fn test() { + let x = loop { + if false { + break; + } + }; +} +"#), + @r###" + 60..137 '{ ... }; }': () + 70..71 'x': () + 74..134 'loop {... }': () + 79..134 '{ ... }': () + 89..128 'if fal... }': () + 92..97 'false': bool + 98..128 '{ ... }': () + 112..117 'break': ! + "### + ); +} -- cgit v1.2.3