aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs252
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 @@
7mod break_outside_of_loop; 7mod break_outside_of_loop;
8mod inactive_code; 8mod inactive_code;
9mod macro_error; 9mod macro_error;
10mod mismatched_arg_count;
10mod missing_fields; 11mod missing_fields;
11mod missing_unsafe; 12mod missing_unsafe;
12mod no_such_field; 13mod 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#"
843fn zero() {}
844fn f() { zero(1); }
845 //^^^^^^^ Expected 0 arguments, found 1
846"#,
847 );
848
849 check_diagnostics(
850 r#"
851fn zero() {}
852fn f() { zero(); }
853"#,
854 );
855 }
856
857 #[test]
858 fn simple_free_fn_one() {
859 check_diagnostics(
860 r#"
861fn one(arg: u8) {}
862fn f() { one(); }
863 //^^^^^ Expected 1 argument, found 0
864"#,
865 );
866
867 check_diagnostics(
868 r#"
869fn one(arg: u8) {}
870fn f() { one(1); }
871"#,
872 );
873 }
874
875 #[test]
876 fn method_as_fn() {
877 check_diagnostics(
878 r#"
879struct S;
880impl S { fn method(&self) {} }
881
882fn f() {
883 S::method();
884} //^^^^^^^^^^^ Expected 1 argument, found 0
885"#,
886 );
887
888 check_diagnostics(
889 r#"
890struct S;
891impl S { fn method(&self) {} }
892
893fn 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#"
905struct S;
906impl 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#"
916struct S;
917impl S { fn method(&self, arg: u8) {} }
918
919fn 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#"
933trait Foo { fn method(&self, arg: usize) {} }
934
935fn f() {
936 let x;
937 x.method();
938}
939"#,
940 );
941 }
942
943 #[test]
944 fn tuple_struct() {
945 check_diagnostics(
946 r#"
947struct Tup(u8, u16);
948fn 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#"
959enum En { Variant(u8, u16), }
960fn 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#"
971macro_rules! Type {
972 () => { u32 };
973}
974enum Foo {
975 Bar(Type![])
976}
977impl 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#"
994extern "C" {
995 fn fixed(fixed: u8);
996 fn varargs(fixed: u8, ...);
997 fn varargs2(...);
998}
999
1000fn 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#"
1020fn 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#"
1036struct C(#[cfg(FALSE)] ());
1037impl C {
1038 fn new() -> Self {
1039 Self(
1040 #[cfg(FALSE)]
1041 (),
1042 )
1043 }
1044
1045 fn method(&self) {}
1046}
1047
1048fn 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#"
1059fn foo(#[cfg(NEVER)] x: ()) {}
1060
1061struct S;
1062
1063impl 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
1069extern "C" {
1070 fn fixed(fixed: u8, #[cfg(NEVER)] ...);
1071 fn varargs(#[cfg(not(NEVER))] ...);
1072}
1073
1074fn 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#"