diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 18:06:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 18:06:25 +0100 |
commit | 8d391ec981562785ec92ce3afe950972c523f925 (patch) | |
tree | 7729eb4ae1ef7a4cf0e0be42dfc2ef36c65cec1e /crates/ide/src/diagnostics.rs | |
parent | bccf77f26cd504de14f7d7d03f9f2a85d0fabb3d (diff) |
internal: refactor mismatched args count diagnostic
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 252 |
1 files changed, 2 insertions, 250 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 67390345f..4c92d0cf4 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -7,6 +7,7 @@ | |||
7 | mod break_outside_of_loop; | 7 | mod break_outside_of_loop; |
8 | mod inactive_code; | 8 | mod inactive_code; |
9 | mod macro_error; | 9 | mod macro_error; |
10 | mod mismatched_arg_count; | ||
10 | mod missing_fields; | 11 | mod missing_fields; |
11 | mod missing_unsafe; | 12 | mod missing_unsafe; |
12 | mod no_such_field; | 13 | mod no_such_field; |
@@ -224,6 +225,7 @@ pub(crate) fn diagnostics( | |||
224 | AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), | 225 | AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), |
225 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), | 226 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), |
226 | AnyDiagnostic::MissingUnsafe(d) => missing_unsafe::missing_unsafe(&ctx, &d), | 227 | AnyDiagnostic::MissingUnsafe(d) => missing_unsafe::missing_unsafe(&ctx, &d), |
228 | AnyDiagnostic::MismatchedArgCount(d) => mismatched_arg_count::mismatched_arg_count(&ctx, &d), | ||
227 | AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d), | 229 | AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d), |
228 | AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d), | 230 | AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d), |
229 | AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), | 231 | AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), |
@@ -837,256 +839,6 @@ fn x(a: S) { | |||
837 | } | 839 | } |
838 | 840 | ||
839 | #[test] | 841 | #[test] |
840 | fn simple_free_fn_zero() { | ||
841 | check_diagnostics( | ||
842 | r#" | ||
843 | fn zero() {} | ||
844 | fn f() { zero(1); } | ||
845 | //^^^^^^^ Expected 0 arguments, found 1 | ||
846 | "#, | ||
847 | ); | ||
848 | |||
849 | check_diagnostics( | ||
850 | r#" | ||
851 | fn zero() {} | ||
852 | fn f() { zero(); } | ||
853 | "#, | ||
854 | ); | ||
855 | } | ||
856 | |||
857 | #[test] | ||
858 | fn simple_free_fn_one() { | ||
859 | check_diagnostics( | ||
860 | r#" | ||
861 | fn one(arg: u8) {} | ||
862 | fn f() { one(); } | ||
863 | //^^^^^ Expected 1 argument, found 0 | ||
864 | "#, | ||
865 | ); | ||
866 | |||
867 | check_diagnostics( | ||
868 | r#" | ||
869 | fn one(arg: u8) {} | ||
870 | fn f() { one(1); } | ||
871 | "#, | ||
872 | ); | ||
873 | } | ||
874 | |||
875 | #[test] | ||
876 | fn method_as_fn() { | ||
877 | check_diagnostics( | ||
878 | r#" | ||
879 | struct S; | ||
880 | impl S { fn method(&self) {} } | ||
881 | |||
882 | fn f() { | ||
883 | S::method(); | ||
884 | } //^^^^^^^^^^^ Expected 1 argument, found 0 | ||
885 | "#, | ||
886 | ); | ||
887 | |||
888 | check_diagnostics( | ||
889 | r#" | ||
890 | struct S; | ||
891 | impl S { fn method(&self) {} } | ||
892 | |||
893 | fn f() { | ||
894 | S::method(&S); | ||
895 | S.method(); | ||
896 | } | ||
897 | "#, | ||
898 | ); | ||
899 | } | ||
900 | |||
901 | #[test] | ||
902 | fn method_with_arg() { | ||
903 | check_diagnostics( | ||
904 | r#" | ||
905 | struct S; | ||
906 | impl S { fn method(&self, arg: u8) {} } | ||
907 | |||
908 | fn f() { | ||
909 | S.method(); | ||
910 | } //^^^^^^^^^^ Expected 1 argument, found 0 | ||
911 | "#, | ||
912 | ); | ||
913 | |||
914 | check_diagnostics( | ||
915 | r#" | ||
916 | struct S; | ||
917 | impl S { fn method(&self, arg: u8) {} } | ||
918 | |||
919 | fn f() { | ||
920 | S::method(&S, 0); | ||
921 | S.method(1); | ||
922 | } | ||
923 | "#, | ||
924 | ); | ||
925 | } | ||
926 | |||
927 | #[test] | ||
928 | fn method_unknown_receiver() { | ||
929 | // note: this is incorrect code, so there might be errors on this in the | ||
930 | // future, but we shouldn't emit an argument count diagnostic here | ||
931 | check_diagnostics( | ||
932 | r#" | ||
933 | trait Foo { fn method(&self, arg: usize) {} } | ||
934 | |||
935 | fn f() { | ||
936 | let x; | ||
937 | x.method(); | ||
938 | } | ||
939 | "#, | ||
940 | ); | ||
941 | } | ||
942 | |||
943 | #[test] | ||
944 | fn tuple_struct() { | ||
945 | check_diagnostics( | ||
946 | r#" | ||
947 | struct Tup(u8, u16); | ||
948 | fn f() { | ||
949 | Tup(0); | ||
950 | } //^^^^^^ Expected 2 arguments, found 1 | ||
951 | "#, | ||
952 | ) | ||
953 | } | ||
954 | |||
955 | #[test] | ||
956 | fn enum_variant() { | ||
957 | check_diagnostics( | ||
958 | r#" | ||
959 | enum En { Variant(u8, u16), } | ||
960 | fn f() { | ||
961 | En::Variant(0); | ||
962 | } //^^^^^^^^^^^^^^ Expected 2 arguments, found 1 | ||
963 | "#, | ||
964 | ) | ||
965 | } | ||
966 | |||
967 | #[test] | ||
968 | fn enum_variant_type_macro() { | ||
969 | check_diagnostics( | ||
970 | r#" | ||
971 | macro_rules! Type { | ||
972 | () => { u32 }; | ||
973 | } | ||
974 | enum Foo { | ||
975 | Bar(Type![]) | ||
976 | } | ||
977 | impl Foo { | ||
978 | fn new() { | ||
979 | Foo::Bar(0); | ||
980 | Foo::Bar(0, 1); | ||
981 | //^^^^^^^^^^^^^^ Expected 1 argument, found 2 | ||
982 | Foo::Bar(); | ||
983 | //^^^^^^^^^^ Expected 1 argument, found 0 | ||
984 | } | ||
985 | } | ||
986 | "#, | ||
987 | ); | ||
988 | } | ||
989 | |||
990 | #[test] | ||
991 | fn varargs() { | ||
992 | check_diagnostics( | ||
993 | r#" | ||
994 | extern "C" { | ||
995 | fn fixed(fixed: u8); | ||
996 | fn varargs(fixed: u8, ...); | ||
997 | fn varargs2(...); | ||
998 | } | ||
999 | |||
1000 | fn f() { | ||
1001 | unsafe { | ||
1002 | fixed(0); | ||
1003 | fixed(0, 1); | ||
1004 | //^^^^^^^^^^^ Expected 1 argument, found 2 | ||
1005 | varargs(0); | ||
1006 | varargs(0, 1); | ||
1007 | varargs2(); | ||
1008 | varargs2(0); | ||
1009 | varargs2(0, 1); | ||
1010 | } | ||
1011 | } | ||
1012 | "#, | ||
1013 | ) | ||
1014 | } | ||
1015 | |||
1016 | #[test] | ||
1017 | fn arg_count_lambda() { | ||
1018 | check_diagnostics( | ||
1019 | r#" | ||
1020 | fn main() { | ||
1021 | let f = |()| (); | ||
1022 | f(); | ||
1023 | //^^^ Expected 1 argument, found 0 | ||
1024 | f(()); | ||
1025 | f((), ()); | ||
1026 | //^^^^^^^^^ Expected 1 argument, found 2 | ||
1027 | } | ||
1028 | "#, | ||
1029 | ) | ||
1030 | } | ||
1031 | |||
1032 | #[test] | ||
1033 | fn cfgd_out_call_arguments() { | ||
1034 | check_diagnostics( | ||
1035 | r#" | ||
1036 | struct C(#[cfg(FALSE)] ()); | ||
1037 | impl C { | ||
1038 | fn new() -> Self { | ||
1039 | Self( | ||
1040 | #[cfg(FALSE)] | ||
1041 | (), | ||
1042 | ) | ||
1043 | } | ||
1044 | |||
1045 | fn method(&self) {} | ||
1046 | } | ||
1047 | |||
1048 | fn main() { | ||
1049 | C::new().method(#[cfg(FALSE)] 0); | ||
1050 | } | ||
1051 | "#, | ||
1052 | ); | ||
1053 | } | ||
1054 | |||
1055 | #[test] | ||
1056 | fn cfgd_out_fn_params() { | ||
1057 | check_diagnostics( | ||
1058 | r#" | ||
1059 | fn foo(#[cfg(NEVER)] x: ()) {} | ||
1060 | |||
1061 | struct S; | ||
1062 | |||
1063 | impl S { | ||
1064 | fn method(#[cfg(NEVER)] self) {} | ||
1065 | fn method2(#[cfg(NEVER)] self, arg: u8) {} | ||
1066 | fn method3(self, #[cfg(NEVER)] arg: u8) {} | ||
1067 | } | ||
1068 | |||
1069 | extern "C" { | ||
1070 | fn fixed(fixed: u8, #[cfg(NEVER)] ...); | ||
1071 | fn varargs(#[cfg(not(NEVER))] ...); | ||
1072 | } | ||
1073 | |||
1074 | fn main() { | ||
1075 | foo(); | ||
1076 | S::method(); | ||
1077 | S::method2(0); | ||
1078 | S::method3(S); | ||
1079 | S.method3(); | ||
1080 | unsafe { | ||
1081 | fixed(0); | ||
1082 | varargs(1, 2, 3); | ||
1083 | } | ||
1084 | } | ||
1085 | "#, | ||
1086 | ) | ||
1087 | } | ||
1088 | |||
1089 | #[test] | ||
1090 | fn missing_semicolon() { | 842 | fn missing_semicolon() { |
1091 | check_diagnostics( | 843 | check_diagnostics( |
1092 | r#" | 844 | r#" |