From bfbc210bc1216b79e355eb70449caf08dc67d5ad Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 22 May 2020 18:15:53 +0200 Subject: Use Chalk's built-in representation of function item types --- crates/ra_hir_ty/src/tests/traits.rs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 6826610cb..17c646076 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -2643,6 +2643,48 @@ fn test() { ); } +#[test] +fn builtin_fn_def_copy() { + assert_snapshot!( + infer_with_mismatches(r#" +#[lang = "copy"] +trait Copy {} + +fn foo() {} +fn bar(T) -> T {} +struct Struct(usize); +enum Enum { Variant(usize) } + +trait Test { fn test(&self) -> bool; } +impl Test for T {} + +fn test() { + foo.test(); + bar.test(); + Struct.test(); + Enum::Variant.test(); +} +"#, true), + // wrong result, because the built-in Copy impl for fn defs doesn't exist in Chalk yet + @r###" + 42..44 '{}': () + 61..62 'T': {unknown} + 69..71 '{}': () + 69..71: expected T, got () + 146..150 'self': &Self + 202..282 '{ ...t(); }': () + 208..211 'foo': fn foo() + 208..218 'foo.test()': {unknown} + 224..227 'bar': fn bar<{unknown}>({unknown}) -> {unknown} + 224..234 'bar.test()': {unknown} + 240..246 'Struct': Struct(usize) -> Struct + 240..253 'Struct.test()': {unknown} + 259..272 'Enum::Variant': Variant(usize) -> Enum + 259..279 'Enum::...test()': {unknown} + "### + ); +} + #[test] fn builtin_sized() { assert_snapshot!( -- cgit v1.2.3 From 194dd9eb0d44284f7e952a1e84296fcda4d90f5e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 22 May 2020 19:13:17 +0200 Subject: Use Chalk's Ty::Function for function pointer types Function pointers can be 'higher-ranked' over lifetimes, which is why they're not an application type in Chalk, but since we don't model lifetimes it doesn't matter for us yet. --- crates/ra_hir_ty/src/tests/traits.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 17c646076..0419bc751 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -2685,6 +2685,38 @@ fn test() { ); } +#[test] +fn builtin_fn_ptr_copy() { + assert_snapshot!( + infer_with_mismatches(r#" +#[lang = "copy"] +trait Copy {} + +trait Test { fn test(&self) -> bool; } +impl Test for T {} + +fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { + f1.test(); + f2.test(); + f3.test(); +} +"#, true), + @r###" + 55..59 'self': &Self + 109..111 'f1': fn() + 119..121 'f2': fn(usize) -> u8 + 140..142 'f3': fn(u8, u8) -> &u8 + 163..211 '{ ...t(); }': () + 169..171 'f1': fn() + 169..178 'f1.test()': bool + 184..186 'f2': fn(usize) -> u8 + 184..193 'f2.test()': bool + 199..201 'f3': fn(u8, u8) -> &u8 + 199..208 'f3.test()': bool + "### + ); +} + #[test] fn builtin_sized() { assert_snapshot!( -- cgit v1.2.3 From 367487fe88dca78cffad5138673d5259f7f7ba6b Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 28 May 2020 21:42:22 +0200 Subject: Support raw_ref_op's raw reference operator --- crates/ra_hir_ty/src/tests/coercion.rs | 17 +++++++++++------ crates/ra_hir_ty/src/tests/simple.rs | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 2cc4f4bf9..6f777ed8c 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -116,15 +116,20 @@ fn infer_let_stmt_coerce() { assert_snapshot!( infer(r#" fn test() { - let x: &[i32] = &[1]; + let x: &[isize] = &[1]; + let x: *const [isize] = &[1]; } "#), @r###" - 11..40 '{ ...[1]; }': () - 21..22 'x': &[i32] - 33..37 '&[1]': &[i32; _] - 34..37 '[1]': [i32; _] - 35..36 '1': i32 + 11..76 '{ ...[1]; }': () + 21..22 'x': &[isize] + 35..39 '&[1]': &[isize; _] + 36..39 '[1]': [isize; _] + 37..38 '1': isize + 49..50 'x': *const [isize] + 69..73 '&[1]': &[isize; _] + 70..73 '[1]': [isize; _] + 71..72 '1': isize "###); } diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index fd2208af2..f1db34160 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -384,6 +384,26 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { ); } +#[test] +fn infer_raw_ref() { + assert_snapshot!( + infer(r#" +fn test(a: i32) { + &raw mut a; + &raw const a; +} +"#), + @r###" + 9..10 'a': i32 + 17..54 '{ ...t a; }': () + 23..33 '&raw mut a': *mut i32 + 32..33 'a': i32 + 39..51 '&raw const a': *const i32 + 50..51 'a': i32 + "### + ); +} + #[test] fn infer_literals() { assert_snapshot!( -- cgit v1.2.3 From 7d0586cb15000193941f93d4b5281e56ef751edd Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 29 May 2020 16:03:06 +0200 Subject: Use first match branch in case of type mismatch, not last The comment says this was intentional, but I do agree with #4304 that it makes more sense the other way around (for if/else as well). Fixes #4304. --- crates/ra_hir_ty/src/tests/simple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index fd2208af2..daa9cc953 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -937,7 +937,7 @@ fn main(foo: Foo) { 51..107 'if tru... }': () 54..58 'true': bool 59..67 '{ }': () - 73..107 'if fal... }': () + 73..107 'if fal... }': i32 76..81 'false': bool 82..107 '{ ... }': i32 92..95 'foo': Foo -- cgit v1.2.3 From ab28f6c24909f2424c6f1d85d1518fa4269fbaae Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 29 May 2020 16:49:52 +0200 Subject: Upgrade Chalk Fixes #4072. --- crates/ra_hir_ty/src/tests/traits.rs | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 0419bc751..e8778d419 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -2665,7 +2665,6 @@ fn test() { Enum::Variant.test(); } "#, true), - // wrong result, because the built-in Copy impl for fn defs doesn't exist in Chalk yet @r###" 42..44 '{}': () 61..62 'T': {unknown} @@ -2674,13 +2673,13 @@ fn test() { 146..150 'self': &Self 202..282 '{ ...t(); }': () 208..211 'foo': fn foo() - 208..218 'foo.test()': {unknown} + 208..218 'foo.test()': bool 224..227 'bar': fn bar<{unknown}>({unknown}) -> {unknown} - 224..234 'bar.test()': {unknown} + 224..234 'bar.test()': bool 240..246 'Struct': Struct(usize) -> Struct - 240..253 'Struct.test()': {unknown} + 240..253 'Struct.test()': bool 259..272 'Enum::Variant': Variant(usize) -> Enum - 259..279 'Enum::...test()': {unknown} + 259..279 'Enum::...test()': bool "### ); } @@ -2754,3 +2753,48 @@ fn test() { "### ); } + +#[test] +fn integer_range_iterate() { + let t = type_at( + r#" +//- /main.rs crate:main deps:std +fn test() { + for x in 0..100 { x<|>; } +} + +//- /std.rs crate:std +pub mod ops { + pub struct Range { + pub start: Idx, + pub end: Idx, + } +} + +pub mod iter { + pub trait Iterator { + type Item; + } + + pub trait IntoIterator { + type Item; + type IntoIter: Iterator; + } + + impl IntoIterator for T where T: Iterator { + type Item = ::Item; + type IntoIter = Self; + } +} + +trait Step {} +impl Step for i32 {} +impl Step for i64 {} + +impl iter::Iterator for ops::Range { + type Item = A; +} +"#, + ); + assert_eq!(t, "i32"); +} -- cgit v1.2.3 From 6f67a46a6a264ac7985a10ee19fbf9bbaef924bc Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 29 May 2020 17:35:57 +0200 Subject: Fix match ergonomics in closure parameters Fixes #4476. --- crates/ra_hir_ty/src/tests/patterns.rs | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index 0c5f972a2..fe62587c0 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -520,3 +520,53 @@ fn main() { 105..107 '()': () ") } + +#[test] +fn match_ergonomics_in_closure_params() { + assert_snapshot!( + infer(r#" +#[lang = "fn_once"] +trait FnOnce { + type Output; +} + +fn foo U>(t: T, f: F) -> U { loop {} } + +fn test() { + foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics + foo(&(1, "a"), |(x, y)| x); +} +"#), + @r###" + 94..95 't': T + 100..101 'f': F + 111..122 '{ loop {} }': U + 113..120 'loop {}': ! + 118..120 '{}': () + 134..233 '{ ... x); }': () + 140..143 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 + 140..167 'foo(&(...y)| x)': i32 + 144..153 '&(1, "a")': &(i32, &str) + 145..153 '(1, "a")': (i32, &str) + 146..147 '1': i32 + 149..152 '"a"': &str + 155..166 '|&(x, y)| x': |&(i32, &str)| -> i32 + 156..163 '&(x, y)': &(i32, &str) + 157..163 '(x, y)': (i32, &str) + 158..159 'x': i32 + 161..162 'y': &str + 165..166 'x': i32 + 204..207 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 + 204..230 'foo(&(...y)| x)': &i32 + 208..217 '&(1, "a")': &(i32, &str) + 209..217 '(1, "a")': (i32, &str) + 210..211 '1': i32 + 213..216 '"a"': &str + 219..229 '|(x, y)| x': |&(i32, &str)| -> &i32 + 220..226 '(x, y)': (i32, &str) + 221..222 'x': &i32 + 224..225 'y': &&str + 228..229 'x': &i32 + "### + ); +} -- cgit v1.2.3 From fb469c3b31e7da962e91269b53b2f53d672cc4ba Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 30 May 2020 02:06:58 +0200 Subject: labelled break test --- crates/ra_hir_ty/src/tests/simple.rs | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 839491b9e..beceb8634 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1943,3 +1943,57 @@ fn test() { "### ); } + +#[test] +fn infer_labelled_break_with_val() { + assert_snapshot!( + infer(r#" +fn foo() { + let _x = || 'outer: loop { + let inner = 'inner: loop { + let i = Default::default(); + if (break 'outer i) { + loop { break 'inner 5i8; }; + } else if true { + break 'inner 6; + } + break 7; + }; + break inner < 8; + }; +} +"#), + @r###" + 10..336 '{ ... }; }': () + 20..22 '_x': || -> bool + 25..333 '|| 'ou... }': || -> bool + 28..333 ''outer... }': bool + 41..333 '{ ... }': () + 55..60 'inner': i32 + 63..301 ''inner... }': i32 + 76..301 '{ ... }': () + 94..95 'i': i32 + 98..114 'Defaul...efault': {unknown} + 98..116 'Defaul...ault()': i32 + 130..270 'if (br... }': () + 134..148 'break 'outer i': ! + 147..148 'i': i32 + 150..209 '{ ... }': () + 168..194 'loop {...5i8; }': i8 + 173..194 '{ brea...5i8; }': () + 175..191 'break ...er 5i8': ! + 188..191 '5i8': i8 + 215..270 'if tru... }': () + 218..222 'true': bool + 223..270 '{ ... }': () + 241..255 'break 'inner 6': ! + 254..255 '6': i32 + 283..290 'break 7': ! + 289..290 '7': i32 + 311..326 'break inner < 8': ! + 317..322 'inner': i32 + 317..326 'inner < 8': bool + 325..326 '8': i32 + "### + ); +} -- cgit v1.2.3 From 1cd78a3355ea70d3070cabb00c80a5d195499752 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 31 May 2020 10:59:40 +0200 Subject: correctly infer labelled breaks --- crates/ra_hir_ty/src/tests/simple.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index beceb8634..88309157b 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1969,17 +1969,17 @@ fn foo() { 25..333 '|| 'ou... }': || -> bool 28..333 ''outer... }': bool 41..333 '{ ... }': () - 55..60 'inner': i32 - 63..301 ''inner... }': i32 + 55..60 'inner': i8 + 63..301 ''inner... }': i8 76..301 '{ ... }': () - 94..95 'i': i32 + 94..95 'i': bool 98..114 'Defaul...efault': {unknown} - 98..116 'Defaul...ault()': i32 + 98..116 'Defaul...ault()': bool 130..270 'if (br... }': () 134..148 'break 'outer i': ! - 147..148 'i': i32 + 147..148 'i': bool 150..209 '{ ... }': () - 168..194 'loop {...5i8; }': i8 + 168..194 'loop {...5i8; }': ! 173..194 '{ brea...5i8; }': () 175..191 'break ...er 5i8': ! 188..191 '5i8': i8 @@ -1987,13 +1987,13 @@ fn foo() { 218..222 'true': bool 223..270 '{ ... }': () 241..255 'break 'inner 6': ! - 254..255 '6': i32 + 254..255 '6': i8 283..290 'break 7': ! - 289..290 '7': i32 + 289..290 '7': i8 311..326 'break inner < 8': ! - 317..322 'inner': i32 + 317..322 'inner': i8 317..326 'inner < 8': bool - 325..326 '8': i32 + 325..326 '8': i8 "### ); } -- cgit v1.2.3