diff options
Diffstat (limited to 'crates/ide_completion')
-rw-r--r-- | crates/ide_completion/src/context.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 787eb2fd3..c929d7394 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -785,6 +785,19 @@ fn foo() { | |||
785 | } | 785 | } |
786 | 786 | ||
787 | #[test] | 787 | #[test] |
788 | fn expected_type_generic_struct_field() { | ||
789 | check_expected_type_and_name( | ||
790 | r#" | ||
791 | struct Foo<T> { a: T } | ||
792 | fn foo() -> Foo<u32> { | ||
793 | Foo { a: $0 } | ||
794 | } | ||
795 | "#, | ||
796 | expect![[r#"ty: u32, name: a"#]], | ||
797 | ) | ||
798 | } | ||
799 | |||
800 | #[test] | ||
788 | fn expected_type_struct_field_with_leading_char() { | 801 | fn expected_type_struct_field_with_leading_char() { |
789 | cov_mark::check!(expected_type_struct_field_with_leading_char); | 802 | cov_mark::check!(expected_type_struct_field_with_leading_char); |
790 | check_expected_type_and_name( | 803 | check_expected_type_and_name( |
@@ -895,4 +908,51 @@ fn foo() -> u32 { | |||
895 | expect![[r#"ty: u32, name: ?"#]], | 908 | expect![[r#"ty: u32, name: ?"#]], |
896 | ) | 909 | ) |
897 | } | 910 | } |
911 | |||
912 | #[test] | ||
913 | fn expected_type_closure_param() { | ||
914 | check_expected_type_and_name( | ||
915 | r#" | ||
916 | fn foo() { | ||
917 | bar(|| $0); | ||
918 | } | ||
919 | |||
920 | fn bar(f: impl FnOnce() -> u32) {} | ||
921 | #[lang = "fn_once"] | ||
922 | trait FnOnce { type Output; } | ||
923 | "#, | ||
924 | expect![[r#"ty: u32, name: ?"#]], | ||
925 | ); | ||
926 | } | ||
927 | |||
928 | #[test] | ||
929 | fn expected_type_generic_function() { | ||
930 | check_expected_type_and_name( | ||
931 | r#" | ||
932 | fn foo() { | ||
933 | bar::<u32>($0); | ||
934 | } | ||
935 | |||
936 | fn bar<T>(t: T) {} | ||
937 | "#, | ||
938 | expect![[r#"ty: u32, name: t"#]], | ||
939 | ); | ||
940 | } | ||
941 | |||
942 | #[test] | ||
943 | fn expected_type_generic_method() { | ||
944 | check_expected_type_and_name( | ||
945 | r#" | ||
946 | fn foo() { | ||
947 | S(1u32).bar($0); | ||
948 | } | ||
949 | |||
950 | struct S<T>(T); | ||
951 | impl<T> S<T> { | ||
952 | fn bar(self, t: T) {} | ||
953 | } | ||
954 | "#, | ||
955 | expect![[r#"ty: u32, name: t"#]], | ||
956 | ); | ||
957 | } | ||
898 | } | 958 | } |