diff options
author | Kevin DeLorey <[email protected]> | 2020-02-09 16:25:47 +0000 |
---|---|---|
committer | Kevin DeLorey <[email protected]> | 2020-02-09 16:37:43 +0000 |
commit | a957c473fdb79880c39b73dc9e0c923093cf16ac (patch) | |
tree | f998b548f530ce604651e0e6af314ed2ec74b3b5 /crates/ra_hir_ty/src/tests/traits.rs | |
parent | 22caf982b99c54058e2e9200aeea0e61cada284a (diff) | |
parent | 1b9b13b4b4a75b5531c3f046ce6bf72d681f2732 (diff) |
Merge branch 'master' into kdelorey/complete-trait-impl
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 316 |
1 files changed, 260 insertions, 56 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 4b268510c..17611ddbf 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
2 | 2 | ||
3 | use ra_db::fixture::WithFixture; | 3 | use ra_db::fixture::WithFixture; |
4 | use test_utils::covers; | ||
5 | 4 | ||
6 | use super::{infer, infer_with_mismatches, type_at, type_at_pos}; | 5 | use super::{infer, infer_with_mismatches, type_at, type_at_pos}; |
7 | use crate::test_db::TestDB; | 6 | use crate::test_db::TestDB; |
@@ -261,10 +260,10 @@ fn test() { | |||
261 | [92; 94) '{}': () | 260 | [92; 94) '{}': () |
262 | [105; 144) '{ ...(s); }': () | 261 | [105; 144) '{ ...(s); }': () |
263 | [115; 116) 's': S<u32> | 262 | [115; 116) 's': S<u32> |
264 | [119; 120) 'S': S<u32>(T) -> S<T> | 263 | [119; 120) 'S': S<u32>(u32) -> S<u32> |
265 | [119; 129) 'S(unknown)': S<u32> | 264 | [119; 129) 'S(unknown)': S<u32> |
266 | [121; 128) 'unknown': u32 | 265 | [121; 128) 'unknown': u32 |
267 | [135; 138) 'foo': fn foo<S<u32>>(T) -> () | 266 | [135; 138) 'foo': fn foo<S<u32>>(S<u32>) -> () |
268 | [135; 141) 'foo(s)': () | 267 | [135; 141) 'foo(s)': () |
269 | [139; 140) 's': S<u32> | 268 | [139; 140) 's': S<u32> |
270 | "### | 269 | "### |
@@ -289,11 +288,11 @@ fn test() { | |||
289 | [98; 100) '{}': () | 288 | [98; 100) '{}': () |
290 | [111; 163) '{ ...(s); }': () | 289 | [111; 163) '{ ...(s); }': () |
291 | [121; 122) 's': S<u32> | 290 | [121; 122) 's': S<u32> |
292 | [125; 126) 'S': S<u32>(T) -> S<T> | 291 | [125; 126) 'S': S<u32>(u32) -> S<u32> |
293 | [125; 135) 'S(unknown)': S<u32> | 292 | [125; 135) 'S(unknown)': S<u32> |
294 | [127; 134) 'unknown': u32 | 293 | [127; 134) 'unknown': u32 |
295 | [145; 146) 'x': u32 | 294 | [145; 146) 'x': u32 |
296 | [154; 157) 'foo': fn foo<u32, S<u32>>(T) -> U | 295 | [154; 157) 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32 |
297 | [154; 160) 'foo(s)': u32 | 296 | [154; 160) 'foo(s)': u32 |
298 | [158; 159) 's': S<u32> | 297 | [158; 159) 's': S<u32> |
299 | "### | 298 | "### |
@@ -358,15 +357,15 @@ fn test() { | |||
358 | [221; 223) '{}': () | 357 | [221; 223) '{}': () |
359 | [234; 300) '{ ...(S); }': () | 358 | [234; 300) '{ ...(S); }': () |
360 | [244; 245) 'x': u32 | 359 | [244; 245) 'x': u32 |
361 | [248; 252) 'foo1': fn foo1<S>(T) -> <T as Iterable>::Item | 360 | [248; 252) 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item |
362 | [248; 255) 'foo1(S)': u32 | 361 | [248; 255) 'foo1(S)': u32 |
363 | [253; 254) 'S': S | 362 | [253; 254) 'S': S |
364 | [265; 266) 'y': u32 | 363 | [265; 266) 'y': u32 |
365 | [269; 273) 'foo2': fn foo2<S>(T) -> <T as Iterable>::Item | 364 | [269; 273) 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item |
366 | [269; 276) 'foo2(S)': u32 | 365 | [269; 276) 'foo2(S)': u32 |
367 | [274; 275) 'S': S | 366 | [274; 275) 'S': S |
368 | [286; 287) 'z': u32 | 367 | [286; 287) 'z': u32 |
369 | [290; 294) 'foo3': fn foo3<S>(T) -> <T as Iterable>::Item | 368 | [290; 294) 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item |
370 | [290; 297) 'foo3(S)': u32 | 369 | [290; 297) 'foo3(S)': u32 |
371 | [295; 296) 'S': S | 370 | [295; 296) 'S': S |
372 | "### | 371 | "### |
@@ -479,7 +478,7 @@ fn indexing_arrays() { | |||
479 | @r###" | 478 | @r###" |
480 | [10; 26) '{ &mut...[2]; }': () | 479 | [10; 26) '{ &mut...[2]; }': () |
481 | [12; 23) '&mut [9][2]': &mut {unknown} | 480 | [12; 23) '&mut [9][2]': &mut {unknown} |
482 | [17; 20) '[9]': [i32;_] | 481 | [17; 20) '[9]': [i32; _] |
483 | [17; 23) '[9][2]': {unknown} | 482 | [17; 23) '[9][2]': {unknown} |
484 | [18; 19) '9': i32 | 483 | [18; 19) '9': i32 |
485 | [21; 22) '2': i32 | 484 | [21; 22) '2': i32 |
@@ -822,8 +821,7 @@ fn test<T: ApplyL>() { | |||
822 | "#, | 821 | "#, |
823 | ); | 822 | ); |
824 | // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types]. | 823 | // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types]. |
825 | // FIXME: fix type parameter names going missing when going through Chalk | 824 | assert_eq!(t, "ApplyL::Out<T>"); |
826 | assert_eq!(t, "ApplyL::Out<[missing name]>"); | ||
827 | } | 825 | } |
828 | 826 | ||
829 | #[test] | 827 | #[test] |
@@ -850,6 +848,198 @@ fn test<T: ApplyL>(t: T) { | |||
850 | } | 848 | } |
851 | 849 | ||
852 | #[test] | 850 | #[test] |
851 | fn argument_impl_trait() { | ||
852 | assert_snapshot!( | ||
853 | infer_with_mismatches(r#" | ||
854 | trait Trait<T> { | ||
855 | fn foo(&self) -> T; | ||
856 | fn foo2(&self) -> i64; | ||
857 | } | ||
858 | fn bar(x: impl Trait<u16>) {} | ||
859 | struct S<T>(T); | ||
860 | impl<T> Trait<T> for S<T> {} | ||
861 | |||
862 | fn test(x: impl Trait<u64>, y: &impl Trait<u32>) { | ||
863 | x; | ||
864 | y; | ||
865 | let z = S(1); | ||
866 | bar(z); | ||
867 | x.foo(); | ||
868 | y.foo(); | ||
869 | z.foo(); | ||
870 | x.foo2(); | ||
871 | y.foo2(); | ||
872 | z.foo2(); | ||
873 | } | ||
874 | "#, true), | ||
875 | @r###" | ||
876 | [30; 34) 'self': &Self | ||
877 | [55; 59) 'self': &Self | ||
878 | [78; 79) 'x': impl Trait<u16> | ||
879 | [98; 100) '{}': () | ||
880 | [155; 156) 'x': impl Trait<u64> | ||
881 | [175; 176) 'y': &impl Trait<u32> | ||
882 | [196; 324) '{ ...2(); }': () | ||
883 | [202; 203) 'x': impl Trait<u64> | ||
884 | [209; 210) 'y': &impl Trait<u32> | ||
885 | [220; 221) 'z': S<u16> | ||
886 | [224; 225) 'S': S<u16>(u16) -> S<u16> | ||
887 | [224; 228) 'S(1)': S<u16> | ||
888 | [226; 227) '1': u16 | ||
889 | [234; 237) 'bar': fn bar(S<u16>) -> () | ||
890 | [234; 240) 'bar(z)': () | ||
891 | [238; 239) 'z': S<u16> | ||
892 | [246; 247) 'x': impl Trait<u64> | ||
893 | [246; 253) 'x.foo()': u64 | ||
894 | [259; 260) 'y': &impl Trait<u32> | ||
895 | [259; 266) 'y.foo()': u32 | ||
896 | [272; 273) 'z': S<u16> | ||
897 | [272; 279) 'z.foo()': u16 | ||
898 | [285; 286) 'x': impl Trait<u64> | ||
899 | [285; 293) 'x.foo2()': i64 | ||
900 | [299; 300) 'y': &impl Trait<u32> | ||
901 | [299; 307) 'y.foo2()': i64 | ||
902 | [313; 314) 'z': S<u16> | ||
903 | [313; 321) 'z.foo2()': i64 | ||
904 | "### | ||
905 | ); | ||
906 | } | ||
907 | |||
908 | #[test] | ||
909 | fn argument_impl_trait_type_args_1() { | ||
910 | assert_snapshot!( | ||
911 | infer_with_mismatches(r#" | ||
912 | trait Trait {} | ||
913 | trait Foo { | ||
914 | // this function has an implicit Self param, an explicit type param, | ||
915 | // and an implicit impl Trait param! | ||
916 | fn bar<T>(x: impl Trait) -> T { loop {} } | ||
917 | } | ||
918 | fn foo<T>(x: impl Trait) -> T { loop {} } | ||
919 | struct S; | ||
920 | impl Trait for S {} | ||
921 | struct F; | ||
922 | impl Foo for F {} | ||
923 | |||
924 | fn test() { | ||
925 | Foo::bar(S); | ||
926 | <F as Foo>::bar(S); | ||
927 | F::bar(S); | ||
928 | Foo::bar::<u32>(S); | ||
929 | <F as Foo>::bar::<u32>(S); | ||
930 | |||
931 | foo(S); | ||
932 | foo::<u32>(S); | ||
933 | foo::<u32, i32>(S); // we should ignore the extraneous i32 | ||
934 | } | ||
935 | "#, true), | ||
936 | @r###" | ||
937 | [156; 157) 'x': impl Trait | ||
938 | [176; 187) '{ loop {} }': T | ||
939 | [178; 185) 'loop {}': ! | ||
940 | [183; 185) '{}': () | ||
941 | [200; 201) 'x': impl Trait | ||
942 | [220; 231) '{ loop {} }': T | ||
943 | [222; 229) 'loop {}': ! | ||
944 | [227; 229) '{}': () | ||
945 | [301; 510) '{ ... i32 }': () | ||
946 | [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown} | ||
947 | [307; 318) 'Foo::bar(S)': {unknown} | ||
948 | [316; 317) 'S': S | ||
949 | [324; 339) '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown} | ||
950 | [324; 342) '<F as ...bar(S)': {unknown} | ||
951 | [340; 341) 'S': S | ||
952 | [348; 354) 'F::bar': fn bar<F, {unknown}>(S) -> {unknown} | ||
953 | [348; 357) 'F::bar(S)': {unknown} | ||
954 | [355; 356) 'S': S | ||
955 | [363; 378) 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32 | ||
956 | [363; 381) 'Foo::b...32>(S)': u32 | ||
957 | [379; 380) 'S': S | ||
958 | [387; 409) '<F as ...:<u32>': fn bar<F, u32>(S) -> u32 | ||
959 | [387; 412) '<F as ...32>(S)': u32 | ||
960 | [410; 411) 'S': S | ||
961 | [419; 422) 'foo': fn foo<{unknown}>(S) -> {unknown} | ||
962 | [419; 425) 'foo(S)': {unknown} | ||
963 | [423; 424) 'S': S | ||
964 | [431; 441) 'foo::<u32>': fn foo<u32>(S) -> u32 | ||
965 | [431; 444) 'foo::<u32>(S)': u32 | ||
966 | [442; 443) 'S': S | ||
967 | [450; 465) 'foo::<u32, i32>': fn foo<u32>(S) -> u32 | ||
968 | [450; 468) 'foo::<...32>(S)': u32 | ||
969 | [466; 467) 'S': S | ||
970 | "### | ||
971 | ); | ||
972 | } | ||
973 | |||
974 | #[test] | ||
975 | fn argument_impl_trait_type_args_2() { | ||
976 | assert_snapshot!( | ||
977 | infer_with_mismatches(r#" | ||
978 | trait Trait {} | ||
979 | struct S; | ||
980 | impl Trait for S {} | ||
981 | struct F<T>; | ||
982 | impl<T> F<T> { | ||
983 | fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} } | ||
984 | } | ||
985 | |||
986 | fn test() { | ||
987 | F.foo(S); | ||
988 | F::<u32>.foo(S); | ||
989 | F::<u32>.foo::<i32>(S); | ||
990 | F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored | ||
991 | } | ||
992 | "#, true), | ||
993 | @r###" | ||
994 | [88; 92) 'self': F<T> | ||
995 | [94; 95) 'x': impl Trait | ||
996 | [119; 130) '{ loop {} }': (T, U) | ||
997 | [121; 128) 'loop {}': ! | ||
998 | [126; 128) '{}': () | ||
999 | [144; 284) '{ ...ored }': () | ||
1000 | [150; 151) 'F': F<{unknown}> | ||
1001 | [150; 158) 'F.foo(S)': ({unknown}, {unknown}) | ||
1002 | [156; 157) 'S': S | ||
1003 | [164; 172) 'F::<u32>': F<u32> | ||
1004 | [164; 179) 'F::<u32>.foo(S)': (u32, {unknown}) | ||
1005 | [177; 178) 'S': S | ||
1006 | [185; 193) 'F::<u32>': F<u32> | ||
1007 | [185; 207) 'F::<u3...32>(S)': (u32, i32) | ||
1008 | [205; 206) 'S': S | ||
1009 | [213; 221) 'F::<u32>': F<u32> | ||
1010 | [213; 240) 'F::<u3...32>(S)': (u32, i32) | ||
1011 | [238; 239) 'S': S | ||
1012 | "### | ||
1013 | ); | ||
1014 | } | ||
1015 | |||
1016 | #[test] | ||
1017 | fn argument_impl_trait_to_fn_pointer() { | ||
1018 | assert_snapshot!( | ||
1019 | infer_with_mismatches(r#" | ||
1020 | trait Trait {} | ||
1021 | fn foo(x: impl Trait) { loop {} } | ||
1022 | struct S; | ||
1023 | impl Trait for S {} | ||
1024 | |||
1025 | fn test() { | ||
1026 | let f: fn(S) -> () = foo; | ||
1027 | } | ||
1028 | "#, true), | ||
1029 | @r###" | ||
1030 | [23; 24) 'x': impl Trait | ||
1031 | [38; 49) '{ loop {} }': () | ||
1032 | [40; 47) 'loop {}': ! | ||
1033 | [45; 47) '{}': () | ||
1034 | [91; 124) '{ ...foo; }': () | ||
1035 | [101; 102) 'f': fn(S) -> () | ||
1036 | [118; 121) 'foo': fn foo(S) -> () | ||
1037 | "### | ||
1038 | ); | ||
1039 | } | ||
1040 | |||
1041 | #[test] | ||
1042 | #[ignore] | ||
853 | fn impl_trait() { | 1043 | fn impl_trait() { |
854 | assert_snapshot!( | 1044 | assert_snapshot!( |
855 | infer(r#" | 1045 | infer(r#" |
@@ -993,34 +1183,23 @@ fn weird_bounds() { | |||
993 | assert_snapshot!( | 1183 | assert_snapshot!( |
994 | infer(r#" | 1184 | infer(r#" |
995 | trait Trait {} | 1185 | trait Trait {} |
996 | fn test() { | 1186 | fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl ('lifetime), e: impl ?Sized, f: impl Trait + ?Sized) { |
997 | let a: impl Trait + 'lifetime = foo; | ||
998 | let b: impl 'lifetime = foo; | ||
999 | let b: impl (Trait) = foo; | ||
1000 | let b: impl ('lifetime) = foo; | ||
1001 | let d: impl ?Sized = foo; | ||
1002 | let e: impl Trait + ?Sized = foo; | ||
1003 | } | 1187 | } |
1004 | "#), | 1188 | "#), |
1005 | @r###" | 1189 | @r###" |
1006 | [26; 237) '{ ...foo; }': () | 1190 | [24; 25) 'a': impl Trait + {error} |
1007 | [36; 37) 'a': impl Trait + {error} | 1191 | [51; 52) 'b': impl {error} |
1008 | [64; 67) 'foo': impl Trait + {error} | 1192 | [70; 71) 'c': impl Trait |
1009 | [77; 78) 'b': impl {error} | 1193 | [87; 88) 'd': impl {error} |
1010 | [97; 100) 'foo': impl {error} | 1194 | [108; 109) 'e': impl {error} |
1011 | [110; 111) 'b': impl Trait | 1195 | [124; 125) 'f': impl Trait + {error} |
1012 | [128; 131) 'foo': impl Trait | 1196 | [148; 151) '{ }': () |
1013 | [141; 142) 'b': impl {error} | ||
1014 | [163; 166) 'foo': impl {error} | ||
1015 | [176; 177) 'd': impl {error} | ||
1016 | [193; 196) 'foo': impl {error} | ||
1017 | [206; 207) 'e': impl Trait + {error} | ||
1018 | [231; 234) 'foo': impl Trait + {error} | ||
1019 | "### | 1197 | "### |
1020 | ); | 1198 | ); |
1021 | } | 1199 | } |
1022 | 1200 | ||
1023 | #[test] | 1201 | #[test] |
1202 | #[ignore] | ||
1024 | fn error_bound_chalk() { | 1203 | fn error_bound_chalk() { |
1025 | let t = type_at( | 1204 | let t = type_at( |
1026 | r#" | 1205 | r#" |
@@ -1076,26 +1255,26 @@ fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) { | |||
1076 | [296; 299) 'get': fn get<T>(T) -> <T as Trait>::Type | 1255 | [296; 299) 'get': fn get<T>(T) -> <T as Trait>::Type |
1077 | [296; 302) 'get(x)': {unknown} | 1256 | [296; 302) 'get(x)': {unknown} |
1078 | [300; 301) 'x': T | 1257 | [300; 301) 'x': T |
1079 | [308; 312) 'get2': fn get2<{unknown}, T>(T) -> U | 1258 | [308; 312) 'get2': fn get2<{unknown}, T>(T) -> {unknown} |
1080 | [308; 315) 'get2(x)': {unknown} | 1259 | [308; 315) 'get2(x)': {unknown} |
1081 | [313; 314) 'x': T | 1260 | [313; 314) 'x': T |
1082 | [321; 324) 'get': fn get<impl Trait<Type = i64>>(T) -> <T as Trait>::Type | 1261 | [321; 324) 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type |
1083 | [321; 327) 'get(y)': {unknown} | 1262 | [321; 327) 'get(y)': {unknown} |
1084 | [325; 326) 'y': impl Trait<Type = i64> | 1263 | [325; 326) 'y': impl Trait<Type = i64> |
1085 | [333; 337) 'get2': fn get2<{unknown}, impl Trait<Type = i64>>(T) -> U | 1264 | [333; 337) 'get2': fn get2<{unknown}, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> {unknown} |
1086 | [333; 340) 'get2(y)': {unknown} | 1265 | [333; 340) 'get2(y)': {unknown} |
1087 | [338; 339) 'y': impl Trait<Type = i64> | 1266 | [338; 339) 'y': impl Trait<Type = i64> |
1088 | [346; 349) 'get': fn get<S<u64>>(T) -> <T as Trait>::Type | 1267 | [346; 349) 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type |
1089 | [346; 357) 'get(set(S))': u64 | 1268 | [346; 357) 'get(set(S))': u64 |
1090 | [350; 353) 'set': fn set<S<u64>>(T) -> T | 1269 | [350; 353) 'set': fn set<S<u64>>(S<u64>) -> S<u64> |
1091 | [350; 356) 'set(S)': S<u64> | 1270 | [350; 356) 'set(S)': S<u64> |
1092 | [354; 355) 'S': S<u64> | 1271 | [354; 355) 'S': S<u64> |
1093 | [363; 367) 'get2': fn get2<u64, S<u64>>(T) -> U | 1272 | [363; 367) 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64 |
1094 | [363; 375) 'get2(set(S))': u64 | 1273 | [363; 375) 'get2(set(S))': u64 |
1095 | [368; 371) 'set': fn set<S<u64>>(T) -> T | 1274 | [368; 371) 'set': fn set<S<u64>>(S<u64>) -> S<u64> |
1096 | [368; 374) 'set(S)': S<u64> | 1275 | [368; 374) 'set(S)': S<u64> |
1097 | [372; 373) 'S': S<u64> | 1276 | [372; 373) 'S': S<u64> |
1098 | [381; 385) 'get2': fn get2<str, S<str>>(T) -> U | 1277 | [381; 385) 'get2': fn get2<str, S<str>>(S<str>) -> str |
1099 | [381; 395) 'get2(S::<str>)': str | 1278 | [381; 395) 'get2(S::<str>)': str |
1100 | [386; 394) 'S::<str>': S<str> | 1279 | [386; 394) 'S::<str>': S<str> |
1101 | "### | 1280 | "### |
@@ -1223,6 +1402,32 @@ fn test<T: Trait1, U: Trait2>(x: T, y: U) { | |||
1223 | } | 1402 | } |
1224 | 1403 | ||
1225 | #[test] | 1404 | #[test] |
1405 | fn super_trait_impl_trait_method_resolution() { | ||
1406 | assert_snapshot!( | ||
1407 | infer(r#" | ||
1408 | mod foo { | ||
1409 | trait SuperTrait { | ||
1410 | fn foo(&self) -> u32 {} | ||
1411 | } | ||
1412 | } | ||
1413 | trait Trait1: foo::SuperTrait {} | ||
1414 | |||
1415 | fn test(x: &impl Trait1) { | ||
1416 | x.foo(); | ||
1417 | } | ||
1418 | "#), | ||
1419 | @r###" | ||
1420 | [50; 54) 'self': &Self | ||
1421 | [63; 65) '{}': () | ||
1422 | [116; 117) 'x': &impl Trait1 | ||
1423 | [133; 149) '{ ...o(); }': () | ||
1424 | [139; 140) 'x': &impl Trait1 | ||
1425 | [139; 146) 'x.foo()': u32 | ||
1426 | "### | ||
1427 | ); | ||
1428 | } | ||
1429 | |||
1430 | #[test] | ||
1226 | fn super_trait_cycle() { | 1431 | fn super_trait_cycle() { |
1227 | // This just needs to not crash | 1432 | // This just needs to not crash |
1228 | assert_snapshot!( | 1433 | assert_snapshot!( |
@@ -1268,9 +1473,9 @@ fn test() { | |||
1268 | [157; 160) '{t}': T | 1473 | [157; 160) '{t}': T |
1269 | [158; 159) 't': T | 1474 | [158; 159) 't': T |
1270 | [259; 280) '{ ...S)); }': () | 1475 | [259; 280) '{ ...S)); }': () |
1271 | [265; 269) 'get2': fn get2<u64, S<u64>>(T) -> U | 1476 | [265; 269) 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64 |
1272 | [265; 277) 'get2(set(S))': u64 | 1477 | [265; 277) 'get2(set(S))': u64 |
1273 | [270; 273) 'set': fn set<S<u64>>(T) -> T | 1478 | [270; 273) 'set': fn set<S<u64>>(S<u64>) -> S<u64> |
1274 | [270; 276) 'set(S)': S<u64> | 1479 | [270; 276) 'set(S)': S<u64> |
1275 | [274; 275) 'S': S<u64> | 1480 | [274; 275) 'S': S<u64> |
1276 | "### | 1481 | "### |
@@ -1332,7 +1537,7 @@ fn test() { | |||
1332 | [173; 175) '{}': () | 1537 | [173; 175) '{}': () |
1333 | [189; 308) '{ ... 1); }': () | 1538 | [189; 308) '{ ... 1); }': () |
1334 | [199; 200) 'x': Option<u32> | 1539 | [199; 200) 'x': Option<u32> |
1335 | [203; 215) 'Option::Some': Some<u32>(T) -> Option<T> | 1540 | [203; 215) 'Option::Some': Some<u32>(u32) -> Option<u32> |
1336 | [203; 221) 'Option...(1u32)': Option<u32> | 1541 | [203; 221) 'Option...(1u32)': Option<u32> |
1337 | [216; 220) '1u32': u32 | 1542 | [216; 220) '1u32': u32 |
1338 | [227; 228) 'x': Option<u32> | 1543 | [227; 228) 'x': Option<u32> |
@@ -1442,7 +1647,7 @@ fn test() { | |||
1442 | [340; 342) '{}': () | 1647 | [340; 342) '{}': () |
1443 | [356; 515) '{ ... S); }': () | 1648 | [356; 515) '{ ... S); }': () |
1444 | [366; 368) 'x1': u64 | 1649 | [366; 368) 'x1': u64 |
1445 | [371; 375) 'foo1': fn foo1<S, u64, |S| -> u64>(T, F) -> U | 1650 | [371; 375) 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 |
1446 | [371; 394) 'foo1(S...hod())': u64 | 1651 | [371; 394) 'foo1(S...hod())': u64 |
1447 | [376; 377) 'S': S | 1652 | [376; 377) 'S': S |
1448 | [379; 393) '|s| s.method()': |S| -> u64 | 1653 | [379; 393) '|s| s.method()': |S| -> u64 |
@@ -1450,7 +1655,7 @@ fn test() { | |||
1450 | [383; 384) 's': S | 1655 | [383; 384) 's': S |
1451 | [383; 393) 's.method()': u64 | 1656 | [383; 393) 's.method()': u64 |
1452 | [404; 406) 'x2': u64 | 1657 | [404; 406) 'x2': u64 |
1453 | [409; 413) 'foo2': fn foo2<S, u64, |S| -> u64>(F, T) -> U | 1658 | [409; 413) 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 |
1454 | [409; 432) 'foo2(|...(), S)': u64 | 1659 | [409; 432) 'foo2(|...(), S)': u64 |
1455 | [414; 428) '|s| s.method()': |S| -> u64 | 1660 | [414; 428) '|s| s.method()': |S| -> u64 |
1456 | [415; 416) 's': S | 1661 | [415; 416) 's': S |
@@ -1603,7 +1808,6 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | |||
1603 | 1808 | ||
1604 | #[test] | 1809 | #[test] |
1605 | fn unify_impl_trait() { | 1810 | fn unify_impl_trait() { |
1606 | covers!(insert_vars_for_impl_trait); | ||
1607 | assert_snapshot!( | 1811 | assert_snapshot!( |
1608 | infer_with_mismatches(r#" | 1812 | infer_with_mismatches(r#" |
1609 | trait Trait<T> {} | 1813 | trait Trait<T> {} |
@@ -1635,26 +1839,26 @@ fn test() -> impl Trait<i32> { | |||
1635 | [172; 183) '{ loop {} }': T | 1839 | [172; 183) '{ loop {} }': T |
1636 | [174; 181) 'loop {}': ! | 1840 | [174; 181) 'loop {}': ! |
1637 | [179; 181) '{}': () | 1841 | [179; 181) '{}': () |
1638 | [214; 310) '{ ...t()) }': S<i32> | 1842 | [214; 310) '{ ...t()) }': S<{unknown}> |
1639 | [224; 226) 's1': S<u32> | 1843 | [224; 226) 's1': S<u32> |
1640 | [229; 230) 'S': S<u32>(T) -> S<T> | 1844 | [229; 230) 'S': S<u32>(u32) -> S<u32> |
1641 | [229; 241) 'S(default())': S<u32> | 1845 | [229; 241) 'S(default())': S<u32> |
1642 | [231; 238) 'default': fn default<u32>() -> T | 1846 | [231; 238) 'default': fn default<u32>() -> u32 |
1643 | [231; 240) 'default()': u32 | 1847 | [231; 240) 'default()': u32 |
1644 | [247; 250) 'foo': fn foo(impl Trait<u32>) -> () | 1848 | [247; 250) 'foo': fn foo(S<u32>) -> () |
1645 | [247; 254) 'foo(s1)': () | 1849 | [247; 254) 'foo(s1)': () |
1646 | [251; 253) 's1': S<u32> | 1850 | [251; 253) 's1': S<u32> |
1647 | [264; 265) 'x': i32 | 1851 | [264; 265) 'x': i32 |
1648 | [273; 276) 'bar': fn bar<i32>(impl Trait<T>) -> T | 1852 | [273; 276) 'bar': fn bar<i32>(S<i32>) -> i32 |
1649 | [273; 290) 'bar(S(...lt()))': i32 | 1853 | [273; 290) 'bar(S(...lt()))': i32 |
1650 | [277; 278) 'S': S<i32>(T) -> S<T> | 1854 | [277; 278) 'S': S<i32>(i32) -> S<i32> |
1651 | [277; 289) 'S(default())': S<i32> | 1855 | [277; 289) 'S(default())': S<i32> |
1652 | [279; 286) 'default': fn default<i32>() -> T | 1856 | [279; 286) 'default': fn default<i32>() -> i32 |
1653 | [279; 288) 'default()': i32 | 1857 | [279; 288) 'default()': i32 |
1654 | [296; 297) 'S': S<i32>(T) -> S<T> | 1858 | [296; 297) 'S': S<{unknown}>({unknown}) -> S<{unknown}> |
1655 | [296; 308) 'S(default())': S<i32> | 1859 | [296; 308) 'S(default())': S<{unknown}> |
1656 | [298; 305) 'default': fn default<i32>() -> T | 1860 | [298; 305) 'default': fn default<{unknown}>() -> {unknown} |
1657 | [298; 307) 'default()': i32 | 1861 | [298; 307) 'default()': {unknown} |
1658 | "### | 1862 | "### |
1659 | ); | 1863 | ); |
1660 | } | 1864 | } |