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/traits.rs') 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 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/traits.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'crates/ra_hir_ty/src/tests/traits.rs') 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/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/tests/traits.rs') 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 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/traits.rs') 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/traits.rs') 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/traits.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/tests/traits.rs') 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/traits.rs') 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/traits.rs') 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/traits.rs') 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/traits.rs') 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/traits.rs') 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