From 9dec65d3b1aa703ceef993e46136f8949d7e0e48 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 24 Jan 2020 16:46:43 +0100 Subject: wip implement lowering mode --- crates/ra_hir_ty/src/tests/traits.rs | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 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 a6ac18f86..764ab2800 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -994,29 +994,17 @@ fn weird_bounds() { assert_snapshot!( infer(r#" trait Trait {} -fn test() { - let a: impl Trait + 'lifetime = foo; - let b: impl 'lifetime = foo; - let b: impl (Trait) = foo; - let b: impl ('lifetime) = foo; - let d: impl ?Sized = foo; - let e: impl Trait + ?Sized = foo; +fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) { } "#), @r###" - [26; 237) '{ ...foo; }': () - [36; 37) 'a': impl Trait + {error} - [64; 67) 'foo': impl Trait + {error} - [77; 78) 'b': impl {error} - [97; 100) 'foo': impl {error} - [110; 111) 'b': impl Trait - [128; 131) 'foo': impl Trait - [141; 142) 'b': impl {error} - [163; 166) 'foo': impl {error} - [176; 177) 'd': impl {error} - [193; 196) 'foo': impl {error} - [206; 207) 'e': impl Trait + {error} - [231; 234) 'foo': impl Trait + {error} + [24; 25) 'a': impl Trait + {error} + [51; 52) 'b': impl {error} + [70; 71) 'c': impl Trait + [87; 88) 'd': impl {error} + [108; 109) 'e': impl {error} + [124; 125) 'f': impl Trait + {error} + [148; 151) '{ }': () "### ); } -- cgit v1.2.3 From 16c69374471a0072541c21a5551b4fd97f7e12ba Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 25 Jan 2020 23:38:33 +0100 Subject: Lower impl trait to variables, move away from using placeholders where they don't belong --- 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 fdab9c187..f1238506b 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1220,7 +1220,7 @@ fn test() { } #[test] -fn infer_impl_generics() { +fn infer_impl_generics_basic() { assert_snapshot!( infer(r#" struct A { -- cgit v1.2.3 From 4789a993eb26963a2411dcc3041733a3b034634a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 28 Jan 2020 21:42:58 +0100 Subject: Fix printing of function types --- crates/ra_hir_ty/src/tests/coercion.rs | 26 +++++++-------- crates/ra_hir_ty/src/tests/method_resolution.rs | 42 ++++++++++++------------- crates/ra_hir_ty/src/tests/patterns.rs | 4 +-- crates/ra_hir_ty/src/tests/regression.rs | 2 +- crates/ra_hir_ty/src/tests/simple.rs | 32 +++++++++---------- crates/ra_hir_ty/src/tests/traits.rs | 32 +++++++++---------- 6 files changed, 69 insertions(+), 69 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 76a1b46c0..fc5ef36a5 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -75,7 +75,7 @@ fn test2() { [124; 131) 'loop {}': ! [129; 131) '{}': () [160; 173) '{ gen() }': *mut [U] - [166; 169) 'gen': fn gen() -> *mut [T; _] + [166; 169) 'gen': fn gen() -> *mut [U; _] [166; 171) 'gen()': *mut [U; _] [186; 420) '{ ...rr); }': () [196; 199) 'arr': &[u8; _] @@ -85,14 +85,14 @@ fn test2() { [227; 228) 'a': &[u8] [237; 240) 'arr': &[u8; _] [250; 251) 'b': u8 - [254; 255) 'f': fn f(&[T]) -> T + [254; 255) 'f': fn f(&[u8]) -> u8 [254; 260) 'f(arr)': u8 [256; 259) 'arr': &[u8; _] [270; 271) 'c': &[u8] [280; 287) '{ arr }': &[u8] [282; 285) 'arr': &[u8; _] [297; 298) 'd': u8 - [301; 302) 'g': fn g(S<&[T]>) -> T + [301; 302) 'g': fn g(S<&[u8]>) -> u8 [301; 316) 'g(S { a: arr })': u8 [303; 315) 'S { a: arr }': S<&[u8]> [310; 313) 'arr': &[u8; _] @@ -164,15 +164,15 @@ fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { [400; 401) 'c': C<[u8; _]> [415; 481) '{ ...(c); }': () [425; 426) 'd': A<[{unknown}]> - [429; 433) 'foo1': fn foo1<{unknown}>(A<[T]>) -> A<[T]> + [429; 433) 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> [429; 436) 'foo1(a)': A<[{unknown}]> [434; 435) 'a': A<[u8; _]> [446; 447) 'e': B<[u8]> - [450; 454) 'foo2': fn foo2(B<[T]>) -> B<[T]> + [450; 454) 'foo2': fn foo2(B<[u8]>) -> B<[u8]> [450; 457) 'foo2(b)': B<[u8]> [455; 456) 'b': B<[u8; _]> [467; 468) 'f': C<[u8]> - [471; 475) 'foo3': fn foo3(C<[T]>) -> C<[T]> + [471; 475) 'foo3': fn foo3(C<[u8]>) -> C<[u8]> [471; 478) 'foo3(c)': C<[u8]> [476; 477) 'c': C<[u8; _]> "### @@ -202,7 +202,7 @@ fn test() { [64; 123) 'if tru... }': &[i32] [67; 71) 'true': bool [72; 97) '{ ... }': &[i32] - [82; 85) 'foo': fn foo(&[T]) -> &[T] + [82; 85) 'foo': fn foo(&[i32]) -> &[i32] [82; 91) 'foo(&[1])': &[i32] [86; 90) '&[1]': &[i32; _] [87; 90) '[1]': [i32; _] @@ -242,7 +242,7 @@ fn test() { [83; 86) '[1]': [i32; _] [84; 85) '1': i32 [98; 123) '{ ... }': &[i32] - [108; 111) 'foo': fn foo(&[T]) -> &[T] + [108; 111) 'foo': fn foo(&[i32]) -> &[i32] [108; 117) 'foo(&[1])': &[i32] [112; 116) '&[1]': &[i32; _] [113; 116) '[1]': [i32; _] @@ -275,7 +275,7 @@ fn test(i: i32) { [70; 147) 'match ... }': &[i32] [76; 77) 'i': i32 [88; 89) '2': i32 - [93; 96) 'foo': fn foo(&[T]) -> &[T] + [93; 96) 'foo': fn foo(&[i32]) -> &[i32] [93; 102) 'foo(&[2])': &[i32] [97; 101) '&[2]': &[i32; _] [98; 101) '[2]': [i32; _] @@ -320,7 +320,7 @@ fn test(i: i32) { [94; 97) '[1]': [i32; _] [95; 96) '1': i32 [107; 108) '2': i32 - [112; 115) 'foo': fn foo(&[T]) -> &[T] + [112; 115) 'foo': fn foo(&[i32]) -> &[i32] [112; 121) 'foo(&[2])': &[i32] [116; 120) '&[2]': &[i32; _] [117; 120) '[2]': [i32; _] @@ -438,16 +438,16 @@ fn test() { [43; 45) '*x': T [44; 45) 'x': &T [58; 127) '{ ...oo); }': () - [64; 73) 'takes_ref': fn takes_ref(&T) -> T + [64; 73) 'takes_ref': fn takes_ref(&Foo) -> Foo [64; 79) 'takes_ref(&Foo)': Foo [74; 78) '&Foo': &Foo [75; 78) 'Foo': Foo - [85; 94) 'takes_ref': fn takes_ref<&Foo>(&T) -> T + [85; 94) 'takes_ref': fn takes_ref<&Foo>(&&Foo) -> &Foo [85; 101) 'takes_...&&Foo)': &Foo [95; 100) '&&Foo': &&Foo [96; 100) '&Foo': &Foo [97; 100) 'Foo': Foo - [107; 116) 'takes_ref': fn takes_ref<&&Foo>(&T) -> T + [107; 116) 'takes_ref': fn takes_ref<&&Foo>(&&&Foo) -> &&Foo [107; 124) 'takes_...&&Foo)': &&Foo [117; 123) '&&&Foo': &&&Foo [118; 123) '&&Foo': &&Foo diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index ce9a06fde..6c7f6706a 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs @@ -27,7 +27,7 @@ fn test() { [66; 73) 'loop {}': ! [71; 73) '{}': () [133; 160) '{ ...o"); }': () - [139; 149) '<[_]>::foo': fn foo(&[T]) -> T + [139; 149) '<[_]>::foo': fn foo(&[u8]) -> u8 [139; 157) '<[_]>:..."foo")': u8 [150; 156) 'b"foo"': &[u8] "### @@ -175,7 +175,7 @@ fn test() { [98; 101) 'val': T [123; 155) '{ ...32); }': () [133; 134) 'a': Gen - [137; 146) 'Gen::make': fn make(T) -> Gen + [137; 146) 'Gen::make': fn make(u32) -> Gen [137; 152) 'Gen::make(0u32)': Gen [147; 151) '0u32': u32 "### @@ -206,7 +206,7 @@ fn test() { [95; 98) '{ }': () [118; 146) '{ ...e(); }': () [128; 129) 'a': Gen - [132; 141) 'Gen::make': fn make() -> Gen + [132; 141) 'Gen::make': fn make() -> Gen [132; 143) 'Gen::make()': Gen "### ); @@ -260,7 +260,7 @@ fn test() { [91; 94) '{ }': () [114; 149) '{ ...e(); }': () [124; 125) 'a': Gen - [128; 144) 'Gen::<...::make': fn make() -> Gen + [128; 144) 'Gen::<...::make': fn make() -> Gen [128; 146) 'Gen::<...make()': Gen "### ); @@ -291,7 +291,7 @@ fn test() { [117; 120) '{ }': () [140; 180) '{ ...e(); }': () [150; 151) 'a': Gen - [154; 175) 'Gen::<...::make': fn make() -> Gen + [154; 175) 'Gen::<...::make': fn make() -> Gen [154; 177) 'Gen::<...make()': Gen "### ); @@ -475,7 +475,7 @@ fn test() { @r###" [33; 37) 'self': &Self [102; 127) '{ ...d(); }': () - [108; 109) 'S': S(T) -> S + [108; 109) 'S': S(u32) -> S [108; 115) 'S(1u32)': S [108; 124) 'S(1u32...thod()': u32 [110; 114) '1u32': u32 @@ -501,13 +501,13 @@ fn test() { @r###" [87; 193) '{ ...t(); }': () [97; 99) 's1': S - [105; 121) 'Defaul...efault': fn default() -> Self + [105; 121) 'Defaul...efault': fn default() -> S [105; 123) 'Defaul...ault()': S [133; 135) 's2': S - [138; 148) 'S::default': fn default() -> Self + [138; 148) 'S::default': fn default() -> S [138; 150) 'S::default()': S [160; 162) 's3': S - [165; 188) '() -> Self + [165; 188) '() -> S [165; 190) '() -> T + [141; 148) 'S::make': fn make() -> u32 [141; 150) 'S::make()': u32 [160; 161) 'b': u64 - [164; 178) 'G::::make': fn make, u64>() -> T + [164; 178) 'G::::make': fn make, u64>() -> u64 [164; 180) 'G::, f64>() -> T + [199; 206) 'G::make': fn make, f64>() -> f64 [199; 208) 'G::make()': f64 "### ); @@ -567,19 +567,19 @@ fn test() { @r###" [135; 313) '{ ...e(); }': () [145; 146) 'a': (u32, i64) - [149; 163) 'S::make::': fn make() -> (T, U) + [149; 163) 'S::make::': fn make() -> (u32, i64) [149; 165) 'S::mak...i64>()': (u32, i64) [175; 176) 'b': (u32, i64) - [189; 196) 'S::make': fn make() -> (T, U) + [189; 196) 'S::make': fn make() -> (u32, i64) [189; 198) 'S::make()': (u32, i64) [208; 209) 'c': (u32, i64) - [212; 233) 'G::': fn make, u32, i64>() -> (T, U) + [212; 233) 'G::': fn make, u32, i64>() -> (u32, i64) [212; 235) 'G::()': (u32, i64) [245; 246) 'd': (u32, i64) - [259; 273) 'G::make::': fn make, u32, i64>() -> (T, U) + [259; 273) 'G::make::': fn make, u32, i64>() -> (u32, i64) [259; 275) 'G::mak...i64>()': (u32, i64) [285; 286) 'e': (u32, i64) - [301; 308) 'G::make': fn make, u32, i64>() -> (T, U) + [301; 308) 'G::make': fn make, u32, i64>() -> (u32, i64) [301; 310) 'G::make()': (u32, i64) "### ); @@ -601,7 +601,7 @@ fn test() { @r###" [101; 127) '{ ...e(); }': () [111; 112) 'a': (S, i64) - [115; 122) 'S::make': fn make, i64>() -> (Self, T) + [115; 122) 'S::make': fn make, i64>() -> (S, i64) [115; 124) 'S::make()': (S, i64) "### ); @@ -625,10 +625,10 @@ fn test() { @r###" [131; 203) '{ ...e(); }': () [141; 142) 'a': (S, i64) - [158; 165) 'S::make': fn make, i64>() -> (Self, T) + [158; 165) 'S::make': fn make, i64>() -> (S, i64) [158; 167) 'S::make()': (S, i64) [177; 178) 'b': (S, i32) - [191; 198) 'S::make': fn make, i32>() -> (Self, T) + [191; 198) 'S::make': fn make, i32>() -> (S, i32) [191; 200) 'S::make()': (S, i32) "### ); @@ -728,7 +728,7 @@ fn test() { [157; 158) 'S': S [157; 165) 'S.into()': u64 [175; 176) 'z': u64 - [179; 196) 'Into::...::into': fn into(Self) -> T + [179; 196) 'Into::...::into': fn into(S) -> u64 [179; 199) 'Into::...nto(S)': u64 [197; 198) 'S': S "### diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index cb3890b42..e25d6dbc4 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -96,13 +96,13 @@ fn test() { [38; 42) 'A(n)': A [40; 41) 'n': &i32 [45; 50) '&A(1)': &A - [46; 47) 'A': A(T) -> A + [46; 47) 'A': A(i32) -> A [46; 50) 'A(1)': A [48; 49) '1': i32 [60; 64) 'A(n)': A [62; 63) 'n': &mut i32 [67; 76) '&mut A(1)': &mut A - [72; 73) 'A': A(T) -> A + [72; 73) 'A': A(i32) -> A [72; 76) 'A(1)': A [74; 75) '1': i32 "### diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 02bab6dbe..14c8ed3a9 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs @@ -346,7 +346,7 @@ pub fn main_loop() { @r###" [144; 146) '{}': () [169; 198) '{ ...t(); }': () - [175; 193) 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet + [175; 193) 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher> [175; 195) 'FxHash...ault()': HashSet<{unknown}, FxHasher> "### ); diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index f1238506b..b08355227 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -754,15 +754,15 @@ fn test() { [289; 295) 'self.0': T [315; 353) '{ ...))); }': () [325; 326) 't': &i32 - [329; 335) 'A::foo': fn foo(&A) -> &T + [329; 335) 'A::foo': fn foo(&A) -> &i32 [329; 350) 'A::foo...42))))': &i32 [336; 349) '&&B(B(A(42)))': &&B>> [337; 349) '&B(B(A(42)))': &B>> - [338; 339) 'B': B>>(T) -> B + [338; 339) 'B': B>>(B>) -> B>> [338; 349) 'B(B(A(42)))': B>> - [340; 341) 'B': B>(T) -> B + [340; 341) 'B': B>(A) -> B> [340; 348) 'B(A(42))': B> - [342; 343) 'A': A(T) -> A + [342; 343) 'A': A(i32) -> A [342; 347) 'A(42)': A [344; 346) '42': i32 "### @@ -817,16 +817,16 @@ fn test(a: A) { [326; 327) 'a': A [337; 383) '{ ...))); }': () [347; 348) 't': &i32 - [351; 352) 'A': A(*mut T) -> A + [351; 352) 'A': A(*mut i32) -> A [351; 365) 'A(0 as *mut _)': A [351; 380) 'A(0 as...B(a)))': &i32 [353; 354) '0': i32 [353; 364) '0 as *mut _': *mut i32 [370; 379) '&&B(B(a))': &&B>> [371; 379) '&B(B(a))': &B>> - [372; 373) 'B': B>>(T) -> B + [372; 373) 'B': B>>(B>) -> B>> [372; 379) 'B(B(a))': B>> - [374; 375) 'B': B>(T) -> B + [374; 375) 'B': B>(A) -> B> [374; 378) 'B(a)': B> [376; 377) 'a': A "### @@ -1205,14 +1205,14 @@ fn test() { [21; 26) '{ t }': T [23; 24) 't': T [38; 98) '{ ...(1); }': () - [44; 46) 'id': fn id(T) -> T + [44; 46) 'id': fn id(u32) -> u32 [44; 52) 'id(1u32)': u32 [47; 51) '1u32': u32 - [58; 68) 'id::': fn id(T) -> T + [58; 68) 'id::': fn id(i128) -> i128 [58; 71) 'id::(1)': i128 [69; 70) '1': i128 [81; 82) 'x': u64 - [90; 92) 'id': fn id(T) -> T + [90; 92) 'id': fn id(u64) -> u64 [90; 95) 'id(1)': u64 [93; 94) '1': u64 "### @@ -1349,16 +1349,16 @@ fn test() -> i128 { [146; 147) 'x': i128 [150; 151) '1': i128 [162; 163) 'y': i128 - [166; 168) 'id': fn id(T) -> T + [166; 168) 'id': fn id(i128) -> i128 [166; 171) 'id(x)': i128 [169; 170) 'x': i128 [182; 183) 'a': A [186; 200) 'A { x: id(y) }': A - [193; 195) 'id': fn id(T) -> T + [193; 195) 'id': fn id(i128) -> i128 [193; 198) 'id(y)': i128 [196; 197) 'y': i128 [211; 212) 'z': i128 - [215; 217) 'id': fn id(T) -> T + [215; 217) 'id': fn id(i128) -> i128 [215; 222) 'id(a.x)': i128 [218; 219) 'a': A [218; 221) 'a.x': i128 @@ -1502,14 +1502,14 @@ fn test() { [78; 158) '{ ...(1); }': () [88; 89) 'y': u32 [92; 97) '10u32': u32 - [103; 105) 'id': fn id(T) -> T + [103; 105) 'id': fn id(u32) -> u32 [103; 108) 'id(y)': u32 [106; 107) 'y': u32 [118; 119) 'x': bool - [128; 133) 'clone': fn clone(&T) -> T + [128; 133) 'clone': fn clone(&bool) -> bool [128; 136) 'clone(z)': bool [134; 135) 'z': &bool - [142; 152) 'id::': fn id(T) -> T + [142; 152) 'id::': fn id(i128) -> i128 [142; 155) 'id::(1)': i128 [153; 154) '1': i128 "### diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 764ab2800..eae6e9681 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -261,10 +261,10 @@ fn test() { [92; 94) '{}': () [105; 144) '{ ...(s); }': () [115; 116) 's': S - [119; 120) 'S': S(T) -> S + [119; 120) 'S': S(u32) -> S [119; 129) 'S(unknown)': S [121; 128) 'unknown': u32 - [135; 138) 'foo': fn foo>(T) -> () + [135; 138) 'foo': fn foo>(S) -> () [135; 141) 'foo(s)': () [139; 140) 's': S "### @@ -289,11 +289,11 @@ fn test() { [98; 100) '{}': () [111; 163) '{ ...(s); }': () [121; 122) 's': S - [125; 126) 'S': S(T) -> S + [125; 126) 'S': S(u32) -> S [125; 135) 'S(unknown)': S [127; 134) 'unknown': u32 [145; 146) 'x': u32 - [154; 157) 'foo': fn foo>(T) -> U + [154; 157) 'foo': fn foo>(S) -> u32 [154; 160) 'foo(s)': u32 [158; 159) 's': S "### @@ -1066,26 +1066,26 @@ fn test>(x: T, y: impl Trait) { [296; 299) 'get': fn get(T) -> ::Type [296; 302) 'get(x)': {unknown} [300; 301) 'x': T - [308; 312) 'get2': fn get2<{unknown}, T>(T) -> U + [308; 312) 'get2': fn get2<{unknown}, T>(T) -> {unknown} [308; 315) 'get2(x)': {unknown} [313; 314) 'x': T - [321; 324) 'get': fn get>(T) -> ::Type + [321; 324) 'get': fn get>(impl Trait) -> as Trait>::Type [321; 327) 'get(y)': {unknown} [325; 326) 'y': impl Trait - [333; 337) 'get2': fn get2<{unknown}, impl Trait>(T) -> U + [333; 337) 'get2': fn get2<{unknown}, impl Trait>(impl Trait) -> {unknown} [333; 340) 'get2(y)': {unknown} [338; 339) 'y': impl Trait - [346; 349) 'get': fn get>(T) -> ::Type + [346; 349) 'get': fn get>(S) -> as Trait>::Type [346; 357) 'get(set(S))': u64 - [350; 353) 'set': fn set>(T) -> T + [350; 353) 'set': fn set>(S) -> S [350; 356) 'set(S)': S [354; 355) 'S': S - [363; 367) 'get2': fn get2>(T) -> U + [363; 367) 'get2': fn get2>(S) -> u64 [363; 375) 'get2(set(S))': u64 - [368; 371) 'set': fn set>(T) -> T + [368; 371) 'set': fn set>(S) -> S [368; 374) 'set(S)': S [372; 373) 'S': S - [381; 385) 'get2': fn get2>(T) -> U + [381; 385) 'get2': fn get2>(S) -> str [381; 395) 'get2(S::)': str [386; 394) 'S::': S "### @@ -1258,9 +1258,9 @@ fn test() { [157; 160) '{t}': T [158; 159) 't': T [259; 280) '{ ...S)); }': () - [265; 269) 'get2': fn get2>(T) -> U + [265; 269) 'get2': fn get2>(S) -> u64 [265; 277) 'get2(set(S))': u64 - [270; 273) 'set': fn set>(T) -> T + [270; 273) 'set': fn set>(S) -> S [270; 276) 'set(S)': S [274; 275) 'S': S "### @@ -1432,7 +1432,7 @@ fn test() { [340; 342) '{}': () [356; 515) '{ ... S); }': () [366; 368) 'x1': u64 - [371; 375) 'foo1': fn foo1 u64>(T, F) -> U + [371; 375) 'foo1': fn foo1 u64>(S, |S| -> u64) -> u64 [371; 394) 'foo1(S...hod())': u64 [376; 377) 'S': S [379; 393) '|s| s.method()': |S| -> u64 @@ -1440,7 +1440,7 @@ fn test() { [383; 384) 's': S [383; 393) 's.method()': u64 [404; 406) 'x2': u64 - [409; 413) 'foo2': fn foo2 u64>(F, T) -> U + [409; 413) 'foo2': fn foo2 u64>(|S| -> u64, S) -> u64 [409; 432) 'foo2(|...(), S)': u64 [414; 428) '|s| s.method()': |S| -> u64 [415; 416) 's': S -- cgit v1.2.3 From a5554dcb17defd2cda729ce0ae732062990391db Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 29 Jan 2020 21:30:24 +0100 Subject: Fix enum constructors --- crates/ra_hir_ty/src/tests/simple.rs | 8 ++++---- crates/ra_hir_ty/src/tests/traits.rs | 2 +- 2 files changed, 5 insertions(+), 5 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 b08355227..3803f5938 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs @@ -1169,16 +1169,16 @@ fn test() { "#), @r###" [76; 184) '{ ...one; }': () - [82; 83) 'A': A(T) -> A + [82; 83) 'A': A(i32) -> A [82; 87) 'A(42)': A [84; 86) '42': i32 - [93; 94) 'A': A(T) -> A + [93; 94) 'A': A(u128) -> A [93; 102) 'A(42u128)': A [95; 101) '42u128': u128 - [108; 112) 'Some': Some<&str>(T) -> Option + [108; 112) 'Some': Some<&str>(&str) -> Option<&str> [108; 117) 'Some("x")': Option<&str> [113; 116) '"x"': &str - [123; 135) 'Option::Some': Some<&str>(T) -> Option + [123; 135) 'Option::Some': Some<&str>(&str) -> Option<&str> [123; 140) 'Option...e("x")': Option<&str> [136; 139) '"x"': &str [146; 150) 'None': Option<{unknown}> diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index eae6e9681..9ff396ad5 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1322,7 +1322,7 @@ fn test() { [173; 175) '{}': () [189; 308) '{ ... 1); }': () [199; 200) 'x': Option - [203; 215) 'Option::Some': Some(T) -> Option + [203; 215) 'Option::Some': Some(u32) -> Option [203; 221) 'Option...(1u32)': Option [216; 220) '1u32': u32 [227; 228) 'x': Option -- cgit v1.2.3 From 4a8279a21ad75ae2cb6d96746b8a880038ec0455 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 15:34:43 +0100 Subject: Fix another test --- crates/ra_hir_ty/src/tests/method_resolution.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 6c7f6706a..446d12813 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs @@ -651,10 +651,10 @@ fn test() { @r###" [107; 211) '{ ...>(); }': () [117; 118) 'a': (S, i64, u8) - [121; 150) '': fn make, i64, u8>() -> (Self, T, U) + [121; 150) '': fn make, i64, u8>() -> (S, i64, u8) [121; 152) '()': (S, i64, u8) [162; 163) 'b': (S, i64, u8) - [182; 206) 'Trait:...::': fn make, i64, u8>() -> (Self, T, U) + [182; 206) 'Trait:...::': fn make, i64, u8>() -> (S, i64, u8) [182; 208) 'Trait:...()': (S, i64, u8) "### ); -- cgit v1.2.3 From 33aa2f8e4f2b9c7c3a6b28427cb6d6f2aef7b802 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 15:57:44 +0100 Subject: Fix assoc type selection --- crates/ra_hir_ty/src/tests/traits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 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 9ff396ad5..e2351ca98 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -358,15 +358,15 @@ fn test() { [221; 223) '{}': () [234; 300) '{ ...(S); }': () [244; 245) 'x': u32 - [248; 252) 'foo1': fn foo1(T) -> ::Item + [248; 252) 'foo1': fn foo1(S) -> ::Item [248; 255) 'foo1(S)': u32 [253; 254) 'S': S [265; 266) 'y': u32 - [269; 273) 'foo2': fn foo2(T) -> ::Item + [269; 273) 'foo2': fn foo2(S) -> ::Item [269; 276) 'foo2(S)': u32 [274; 275) 'S': S [286; 287) 'z': u32 - [290; 294) 'foo3': fn foo3(T) -> ::Item + [290; 294) 'foo3': fn foo3(S) -> ::Item [290; 297) 'foo3(S)': u32 [295; 296) 'S': S "### -- cgit v1.2.3 From f8b7b64bce772f21124b4790538ca97418cc23ca Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 16:05:58 +0100 Subject: WIP use params for APIT --- crates/ra_hir_ty/src/tests/traits.rs | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 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 e2351ca98..dc78e83cd 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -849,6 +849,59 @@ fn test(t: T) { assert_eq!(t, "{unknown}"); } +#[test] +fn argument_impl_trait() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait { + fn foo(&self) -> T; + fn foo2(&self) -> i64; +} +fn bar(impl Trait) {} +struct S(T); +impl Trait for S {} + +fn test(x: impl Trait, y: &impl Trait) { + x; + y; + let z = S(1); + bar(z); + x.foo(); + y.foo(); + z.foo(); + x.foo2(); + y.foo2(); + z.foo2(); +} +"#, true), + @r###" + [30; 34) 'self': &Self + [55; 59) 'self': &Self + [99; 101) '{}': () + [111; 112) 'x': impl Trait + [131; 132) 'y': &impl Trait + [152; 269) '{ ...2(); }': () + [158; 159) 'x': impl Trait + [165; 166) 'y': &impl Trait + [176; 177) 'z': impl Trait + [180; 183) 'bar': fn bar() -> impl Trait + [180; 185) 'bar()': impl Trait + [191; 192) 'x': impl Trait + [191; 198) 'x.foo()': u64 + [204; 205) 'y': &impl Trait + [204; 211) 'y.foo()': u64 + [217; 218) 'z': impl Trait + [217; 224) 'z.foo()': u64 + [230; 231) 'x': impl Trait + [230; 238) 'x.foo2()': i64 + [244; 245) 'y': &impl Trait + [244; 252) 'y.foo2()': i64 + [258; 259) 'z': impl Trait + [258; 266) 'z.foo2()': i64 + "### + ); +} + #[test] #[ignore] fn impl_trait() { -- cgit v1.2.3 From ed25cf70d5e0df9c7a33deb503ea14c2d97bd7a7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 16:52:43 +0100 Subject: Change Ty::Param to contain param ID --- crates/ra_hir_ty/src/tests/method_resolution.rs | 2 +- crates/ra_hir_ty/src/tests/traits.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 446d12813..1722563aa 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs @@ -697,7 +697,7 @@ fn test>(t: T) { [71; 72) 't': T [77; 96) '{ ...d(); }': () [83; 84) 't': T - [83; 93) 't.method()': [missing name] + [83; 93) 't.method()': U "### ); } diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index dc78e83cd..e6f697fa3 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -822,8 +822,7 @@ fn test() { "#, ); // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types]. - // FIXME: fix type parameter names going missing when going through Chalk - assert_eq!(t, "ApplyL::Out<[missing name]>"); + assert_eq!(t, "ApplyL::Out"); } #[test] -- cgit v1.2.3 From 3397ca679fb0156c9f102ab82354e2bcef5f4dd1 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 2 Feb 2020 13:04:22 +0100 Subject: Fix APIT some more --- crates/ra_hir_ty/src/tests/traits.rs | 51 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 23 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 e6f697fa3..bae5eae07 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -856,11 +856,11 @@ trait Trait { fn foo(&self) -> T; fn foo2(&self) -> i64; } -fn bar(impl Trait) {} +fn bar(x: impl Trait) {} struct S(T); impl Trait for S {} -fn test(x: impl Trait, y: &impl Trait) { +fn test(x: impl Trait, y: &impl Trait) { x; y; let z = S(1); @@ -876,27 +876,32 @@ fn test(x: impl Trait, y: &impl Trait) { @r###" [30; 34) 'self': &Self [55; 59) 'self': &Self - [99; 101) '{}': () - [111; 112) 'x': impl Trait - [131; 132) 'y': &impl Trait - [152; 269) '{ ...2(); }': () - [158; 159) 'x': impl Trait - [165; 166) 'y': &impl Trait - [176; 177) 'z': impl Trait - [180; 183) 'bar': fn bar() -> impl Trait - [180; 185) 'bar()': impl Trait - [191; 192) 'x': impl Trait - [191; 198) 'x.foo()': u64 - [204; 205) 'y': &impl Trait - [204; 211) 'y.foo()': u64 - [217; 218) 'z': impl Trait - [217; 224) 'z.foo()': u64 - [230; 231) 'x': impl Trait - [230; 238) 'x.foo2()': i64 - [244; 245) 'y': &impl Trait - [244; 252) 'y.foo2()': i64 - [258; 259) 'z': impl Trait - [258; 266) 'z.foo2()': i64 + [78; 79) 'x': impl Trait + [98; 100) '{}': () + [155; 156) 'x': impl Trait + [175; 176) 'y': &impl Trait + [196; 324) '{ ...2(); }': () + [202; 203) 'x': impl Trait + [209; 210) 'y': &impl Trait + [220; 221) 'z': S + [224; 225) 'S': S(u16) -> S + [224; 228) 'S(1)': S + [226; 227) '1': u16 + [234; 237) 'bar': fn bar>(S) -> () + [234; 240) 'bar(z)': () + [238; 239) 'z': S + [246; 247) 'x': impl Trait + [246; 253) 'x.foo()': u64 + [259; 260) 'y': &impl Trait + [259; 266) 'y.foo()': u32 + [272; 273) 'z': S + [272; 279) 'z.foo()': u16 + [285; 286) 'x': impl Trait + [285; 293) 'x.foo2()': i64 + [299; 300) 'y': &impl Trait + [299; 307) 'y.foo2()': i64 + [313; 314) 'z': S + [313; 321) 'z.foo2()': i64 "### ); } -- cgit v1.2.3 From 6787f124b5557120cd1e4557cbdb59aa7f215be6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 15:13:00 +0100 Subject: Clean up RPIT a bit --- crates/ra_hir_ty/src/tests/traits.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 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 bae5eae07..134cea8d8 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1,7 +1,6 @@ use insta::assert_snapshot; use ra_db::fixture::WithFixture; -use test_utils::covers; use super::{infer, infer_with_mismatches, type_at, type_at_pos}; use crate::test_db::TestDB; @@ -1650,7 +1649,6 @@ fn test() where T: Trait, U: Trait { #[test] fn unify_impl_trait() { - covers!(insert_vars_for_impl_trait); assert_snapshot!( infer_with_mismatches(r#" trait Trait {} @@ -1682,26 +1680,26 @@ fn test() -> impl Trait { [172; 183) '{ loop {} }': T [174; 181) 'loop {}': ! [179; 181) '{}': () - [214; 310) '{ ...t()) }': S + [214; 310) '{ ...t()) }': S<{unknown}> [224; 226) 's1': S - [229; 230) 'S': S(T) -> S + [229; 230) 'S': S(u32) -> S [229; 241) 'S(default())': S - [231; 238) 'default': fn default() -> T + [231; 238) 'default': fn default() -> u32 [231; 240) 'default()': u32 - [247; 250) 'foo': fn foo(impl Trait) -> () + [247; 250) 'foo': fn foo>(S) -> () [247; 254) 'foo(s1)': () [251; 253) 's1': S [264; 265) 'x': i32 - [273; 276) 'bar': fn bar(impl Trait) -> T + [273; 276) 'bar': fn bar>(S) -> i32 [273; 290) 'bar(S(...lt()))': i32 - [277; 278) 'S': S(T) -> S + [277; 278) 'S': S(i32) -> S [277; 289) 'S(default())': S - [279; 286) 'default': fn default() -> T + [279; 286) 'default': fn default() -> i32 [279; 288) 'default()': i32 - [296; 297) 'S': S(T) -> S - [296; 308) 'S(default())': S - [298; 305) 'default': fn default() -> T - [298; 307) 'default()': i32 + [296; 297) 'S': S<{unknown}>({unknown}) -> S<{unknown}> + [296; 308) 'S(default())': S<{unknown}> + [298; 305) 'default': fn default<{unknown}>() -> {unknown} + [298; 307) 'default()': {unknown} "### ); } -- cgit v1.2.3 From 6c70619b0126bc0e40bd9df39dcd6e711cac69c5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 16:24:09 +0100 Subject: Deal better with implicit type parameters and argument lists --- crates/ra_hir_ty/src/tests/traits.rs | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 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 134cea8d8..f90dadc08 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -905,6 +905,114 @@ fn test(x: impl Trait, y: &impl Trait) { ); } +#[test] +fn argument_impl_trait_type_args_1() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +trait Foo { + // this function has an implicit Self param, an explicit type param, + // and an implicit impl Trait param! + fn bar(x: impl Trait) -> T { loop {} } +} +fn foo(x: impl Trait) -> T { loop {} } +struct S; +impl Trait for S {} +struct F; +impl Foo for F {} + +fn test() { + Foo::bar(S); + ::bar(S); + F::bar(S); + Foo::bar::(S); + ::bar::(S); + + foo(S); + foo::(S); + foo::(S); // we should ignore the extraneous i32 +} +"#, true), + @r###" + [156; 157) 'x': impl Trait + [176; 187) '{ loop {} }': T + [178; 185) 'loop {}': ! + [183; 185) '{}': () + [200; 201) 'x': impl Trait + [220; 231) '{ loop {} }': T + [222; 229) 'loop {}': ! + [227; 229) '{}': () + [301; 510) '{ ... i32 }': () + [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}, S>(S) -> {unknown} + [307; 318) 'Foo::bar(S)': {unknown} + [316; 317) 'S': S + [324; 339) '::bar': fn bar(S) -> {unknown} + [324; 342) '(S) -> {unknown} + [348; 357) 'F::bar(S)': {unknown} + [355; 356) 'S': S + [363; 378) 'Foo::bar::': fn bar<{unknown}, u32, S>(S) -> u32 + [363; 381) 'Foo::b...32>(S)': u32 + [379; 380) 'S': S + [387; 409) '': fn bar(S) -> u32 + [387; 412) '(S)': u32 + [410; 411) 'S': S + [419; 422) 'foo': fn foo<{unknown}, S>(S) -> {unknown} + [419; 425) 'foo(S)': {unknown} + [423; 424) 'S': S + [431; 441) 'foo::': fn foo(S) -> u32 + [431; 444) 'foo::(S)': u32 + [442; 443) 'S': S + [450; 465) 'foo::': fn foo(S) -> u32 + [450; 468) 'foo::<...32>(S)': u32 + [466; 467) 'S': S + "### + ); +} + +#[test] +fn argument_impl_trait_type_args_2() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +struct S; +impl Trait for S {} +struct F; +impl F { + fn foo(self, x: impl Trait) -> (T, U) { loop {} } +} + +fn test() { + F.foo(S); + F::.foo(S); + F::.foo::(S); + F::.foo::(S); // extraneous argument should be ignored +} +"#, true), + @r###" + [88; 92) 'self': F + [94; 95) 'x': impl Trait + [119; 130) '{ loop {} }': (T, U) + [121; 128) 'loop {}': ! + [126; 128) '{}': () + [144; 284) '{ ...ored }': () + [150; 151) 'F': F<{unknown}> + [150; 158) 'F.foo(S)': ({unknown}, {unknown}) + [156; 157) 'S': S + [164; 172) 'F::': F + [164; 179) 'F::.foo(S)': (u32, {unknown}) + [177; 178) 'S': S + [185; 193) 'F::': F + [185; 207) 'F::(S)': (u32, i32) + [205; 206) 'S': S + [213; 221) 'F::': F + [213; 240) 'F::(S)': (u32, i32) + [238; 239) 'S': S + "### + ); +} + #[test] #[ignore] fn impl_trait() { -- cgit v1.2.3 From b0bb8622eea7cb447ebadb8b5fba43850305e913 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 16:39:48 +0100 Subject: Don't print implicit type args from impl Trait --- crates/ra_hir_ty/src/tests/traits.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 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 f90dadc08..c6851fb69 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -886,7 +886,7 @@ fn test(x: impl Trait, y: &impl Trait) { [224; 225) 'S': S(u16) -> S [224; 228) 'S(1)': S [226; 227) '1': u16 - [234; 237) 'bar': fn bar>(S) -> () + [234; 237) 'bar': fn bar(S) -> () [234; 240) 'bar(z)': () [238; 239) 'z': S [246; 247) 'x': impl Trait @@ -943,28 +943,28 @@ fn test() { [222; 229) 'loop {}': ! [227; 229) '{}': () [301; 510) '{ ... i32 }': () - [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}, S>(S) -> {unknown} + [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown} [307; 318) 'Foo::bar(S)': {unknown} [316; 317) 'S': S - [324; 339) '::bar': fn bar(S) -> {unknown} + [324; 339) '::bar': fn bar(S) -> {unknown} [324; 342) '(S) -> {unknown} + [348; 354) 'F::bar': fn bar(S) -> {unknown} [348; 357) 'F::bar(S)': {unknown} [355; 356) 'S': S - [363; 378) 'Foo::bar::': fn bar<{unknown}, u32, S>(S) -> u32 + [363; 378) 'Foo::bar::': fn bar<{unknown}, u32>(S) -> u32 [363; 381) 'Foo::b...32>(S)': u32 [379; 380) 'S': S - [387; 409) '': fn bar(S) -> u32 + [387; 409) '': fn bar(S) -> u32 [387; 412) '(S)': u32 [410; 411) 'S': S - [419; 422) 'foo': fn foo<{unknown}, S>(S) -> {unknown} + [419; 422) 'foo': fn foo<{unknown}>(S) -> {unknown} [419; 425) 'foo(S)': {unknown} [423; 424) 'S': S - [431; 441) 'foo::': fn foo(S) -> u32 + [431; 441) 'foo::': fn foo(S) -> u32 [431; 444) 'foo::(S)': u32 [442; 443) 'S': S - [450; 465) 'foo::': fn foo(S) -> u32 + [450; 465) 'foo::': fn foo(S) -> u32 [450; 468) 'foo::<...32>(S)': u32 [466; 467) 'S': S "### @@ -1794,11 +1794,11 @@ fn test() -> impl Trait { [229; 241) 'S(default())': S [231; 238) 'default': fn default() -> u32 [231; 240) 'default()': u32 - [247; 250) 'foo': fn foo>(S) -> () + [247; 250) 'foo': fn foo(S) -> () [247; 254) 'foo(s1)': () [251; 253) 's1': S [264; 265) 'x': i32 - [273; 276) 'bar': fn bar>(S) -> i32 + [273; 276) 'bar': fn bar(S) -> i32 [273; 290) 'bar(S(...lt()))': i32 [277; 278) 'S': S(i32) -> S [277; 289) 'S(default())': S -- cgit v1.2.3 From eefe02ce6e1750b771cf99125429358e87485745 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 18:27:54 +0100 Subject: Add two more tests --- crates/ra_hir_ty/src/tests/traits.rs | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 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 c6851fb69..17611ddbf 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1013,6 +1013,31 @@ fn test() { ); } +#[test] +fn argument_impl_trait_to_fn_pointer() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +fn foo(x: impl Trait) { loop {} } +struct S; +impl Trait for S {} + +fn test() { + let f: fn(S) -> () = foo; +} +"#, true), + @r###" + [23; 24) 'x': impl Trait + [38; 49) '{ loop {} }': () + [40; 47) 'loop {}': ! + [45; 47) '{}': () + [91; 124) '{ ...foo; }': () + [101; 102) 'f': fn(S) -> () + [118; 121) 'foo': fn foo(S) -> () + "### + ); +} + #[test] #[ignore] fn impl_trait() { @@ -1376,6 +1401,32 @@ fn test(x: T, y: U) { ); } +#[test] +fn super_trait_impl_trait_method_resolution() { + assert_snapshot!( + infer(r#" +mod foo { + trait SuperTrait { + fn foo(&self) -> u32 {} + } +} +trait Trait1: foo::SuperTrait {} + +fn test(x: &impl Trait1) { + x.foo(); +} +"#), + @r###" + [50; 54) 'self': &Self + [63; 65) '{}': () + [116; 117) 'x': &impl Trait1 + [133; 149) '{ ...o(); }': () + [139; 140) 'x': &impl Trait1 + [139; 146) 'x.foo()': u32 + "### + ); +} + #[test] fn super_trait_cycle() { // This just needs to not crash -- cgit v1.2.3