diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/_match.rs | 772 |
1 files changed, 385 insertions, 387 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index 42004282c..02a7a61f1 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs | |||
@@ -842,194 +842,193 @@ mod tests { | |||
842 | 842 | ||
843 | pub(super) use crate::{diagnostics::MissingMatchArms, test_db::TestDB}; | 843 | pub(super) use crate::{diagnostics::MissingMatchArms, test_db::TestDB}; |
844 | 844 | ||
845 | pub(super) fn check_diagnostic_message(content: &str) -> String { | 845 | pub(super) fn check_diagnostic_message(ra_fixture: &str) -> String { |
846 | TestDB::with_single_file(content).0.diagnostic::<MissingMatchArms>().0 | 846 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().0 |
847 | } | 847 | } |
848 | 848 | ||
849 | pub(super) fn check_diagnostic(content: &str) { | 849 | pub(super) fn check_diagnostic(ra_fixture: &str) { |
850 | let diagnostic_count = | 850 | let diagnostic_count = |
851 | TestDB::with_single_file(content).0.diagnostic::<MissingMatchArms>().1; | 851 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().1; |
852 | 852 | ||
853 | assert_eq!(1, diagnostic_count, "no diagnostic reported"); | 853 | assert_eq!(1, diagnostic_count, "no diagnostic reported"); |
854 | } | 854 | } |
855 | 855 | ||
856 | pub(super) fn check_no_diagnostic(content: &str) { | 856 | pub(super) fn check_no_diagnostic(ra_fixture: &str) { |
857 | let diagnostic_count = | 857 | let diagnostic_count = |
858 | TestDB::with_single_file(content).0.diagnostic::<MissingMatchArms>().1; | 858 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().1; |
859 | 859 | ||
860 | assert_eq!(0, diagnostic_count, "expected no diagnostic, found one"); | 860 | assert_eq!(0, diagnostic_count, "expected no diagnostic, found one"); |
861 | } | 861 | } |
862 | 862 | ||
863 | #[test] | 863 | #[test] |
864 | fn empty_tuple_no_arms_diagnostic_message() { | 864 | fn empty_tuple_no_arms_diagnostic_message() { |
865 | let content = r" | ||
866 | fn test_fn() { | ||
867 | match () { | ||
868 | } | ||
869 | } | ||
870 | "; | ||
871 | |||
872 | assert_snapshot!( | 865 | assert_snapshot!( |
873 | check_diagnostic_message(content), | 866 | check_diagnostic_message(r" |
867 | fn test_fn() { | ||
868 | match () { | ||
869 | } | ||
870 | } | ||
871 | "), | ||
874 | @"\"()\": Missing match arm\n" | 872 | @"\"()\": Missing match arm\n" |
875 | ); | 873 | ); |
876 | } | 874 | } |
877 | 875 | ||
878 | #[test] | 876 | #[test] |
879 | fn empty_tuple_no_arms() { | 877 | fn empty_tuple_no_arms() { |
880 | let content = r" | 878 | check_diagnostic( |
879 | r" | ||
881 | fn test_fn() { | 880 | fn test_fn() { |
882 | match () { | 881 | match () { |
883 | } | 882 | } |
884 | } | 883 | } |
885 | "; | 884 | ", |
886 | 885 | ); | |
887 | check_diagnostic(content); | ||
888 | } | 886 | } |
889 | 887 | ||
890 | #[test] | 888 | #[test] |
891 | fn empty_tuple_wild() { | 889 | fn empty_tuple_wild() { |
892 | let content = r" | 890 | check_no_diagnostic( |
891 | r" | ||
893 | fn test_fn() { | 892 | fn test_fn() { |
894 | match () { | 893 | match () { |
895 | _ => {} | 894 | _ => {} |
896 | } | 895 | } |
897 | } | 896 | } |
898 | "; | 897 | ", |
899 | 898 | ); | |
900 | check_no_diagnostic(content); | ||
901 | } | 899 | } |
902 | 900 | ||
903 | #[test] | 901 | #[test] |
904 | fn empty_tuple_no_diagnostic() { | 902 | fn empty_tuple_no_diagnostic() { |
905 | let content = r" | 903 | check_no_diagnostic( |
904 | r" | ||
906 | fn test_fn() { | 905 | fn test_fn() { |
907 | match () { | 906 | match () { |
908 | () => {} | 907 | () => {} |
909 | } | 908 | } |
910 | } | 909 | } |
911 | "; | 910 | ", |
912 | 911 | ); | |
913 | check_no_diagnostic(content); | ||
914 | } | 912 | } |
915 | 913 | ||
916 | #[test] | 914 | #[test] |
917 | fn tuple_of_empty_tuple_no_arms() { | 915 | fn tuple_of_empty_tuple_no_arms() { |
918 | let content = r" | 916 | check_diagnostic( |
917 | r" | ||
919 | fn test_fn() { | 918 | fn test_fn() { |
920 | match (()) { | 919 | match (()) { |
921 | } | 920 | } |
922 | } | 921 | } |
923 | "; | 922 | ", |
924 | 923 | ); | |
925 | check_diagnostic(content); | ||
926 | } | 924 | } |
927 | 925 | ||
928 | #[test] | 926 | #[test] |
929 | fn tuple_of_empty_tuple_no_diagnostic() { | 927 | fn tuple_of_empty_tuple_no_diagnostic() { |
930 | let content = r" | 928 | check_no_diagnostic( |
929 | r" | ||
931 | fn test_fn() { | 930 | fn test_fn() { |
932 | match (()) { | 931 | match (()) { |
933 | (()) => {} | 932 | (()) => {} |
934 | } | 933 | } |
935 | } | 934 | } |
936 | "; | 935 | ", |
937 | 936 | ); | |
938 | check_no_diagnostic(content); | ||
939 | } | 937 | } |
940 | 938 | ||
941 | #[test] | 939 | #[test] |
942 | fn tuple_of_two_empty_tuple_no_arms() { | 940 | fn tuple_of_two_empty_tuple_no_arms() { |
943 | let content = r" | 941 | check_diagnostic( |
942 | r" | ||
944 | fn test_fn() { | 943 | fn test_fn() { |
945 | match ((), ()) { | 944 | match ((), ()) { |
946 | } | 945 | } |
947 | } | 946 | } |
948 | "; | 947 | ", |
949 | 948 | ); | |
950 | check_diagnostic(content); | ||
951 | } | 949 | } |
952 | 950 | ||
953 | #[test] | 951 | #[test] |
954 | fn tuple_of_two_empty_tuple_no_diagnostic() { | 952 | fn tuple_of_two_empty_tuple_no_diagnostic() { |
955 | let content = r" | 953 | check_no_diagnostic( |
954 | r" | ||
956 | fn test_fn() { | 955 | fn test_fn() { |
957 | match ((), ()) { | 956 | match ((), ()) { |
958 | ((), ()) => {} | 957 | ((), ()) => {} |
959 | } | 958 | } |
960 | } | 959 | } |
961 | "; | 960 | ", |
962 | 961 | ); | |
963 | check_no_diagnostic(content); | ||
964 | } | 962 | } |
965 | 963 | ||
966 | #[test] | 964 | #[test] |
967 | fn bool_no_arms() { | 965 | fn bool_no_arms() { |
968 | let content = r" | 966 | check_diagnostic( |
967 | r" | ||
969 | fn test_fn() { | 968 | fn test_fn() { |
970 | match false { | 969 | match false { |
971 | } | 970 | } |
972 | } | 971 | } |
973 | "; | 972 | ", |
974 | 973 | ); | |
975 | check_diagnostic(content); | ||
976 | } | 974 | } |
977 | 975 | ||
978 | #[test] | 976 | #[test] |
979 | fn bool_missing_arm() { | 977 | fn bool_missing_arm() { |
980 | let content = r" | 978 | check_diagnostic( |
979 | r" | ||
981 | fn test_fn() { | 980 | fn test_fn() { |
982 | match false { | 981 | match false { |
983 | true => {} | 982 | true => {} |
984 | } | 983 | } |
985 | } | 984 | } |
986 | "; | 985 | ", |
987 | 986 | ); | |
988 | check_diagnostic(content); | ||
989 | } | 987 | } |
990 | 988 | ||
991 | #[test] | 989 | #[test] |
992 | fn bool_no_diagnostic() { | 990 | fn bool_no_diagnostic() { |
993 | let content = r" | 991 | check_no_diagnostic( |
992 | r" | ||
994 | fn test_fn() { | 993 | fn test_fn() { |
995 | match false { | 994 | match false { |
996 | true => {} | 995 | true => {} |
997 | false => {} | 996 | false => {} |
998 | } | 997 | } |
999 | } | 998 | } |
1000 | "; | 999 | ", |
1001 | 1000 | ); | |
1002 | check_no_diagnostic(content); | ||
1003 | } | 1001 | } |
1004 | 1002 | ||
1005 | #[test] | 1003 | #[test] |
1006 | fn tuple_of_bools_no_arms() { | 1004 | fn tuple_of_bools_no_arms() { |
1007 | let content = r" | 1005 | check_diagnostic( |
1006 | r" | ||
1008 | fn test_fn() { | 1007 | fn test_fn() { |
1009 | match (false, true) { | 1008 | match (false, true) { |
1010 | } | 1009 | } |
1011 | } | 1010 | } |
1012 | "; | 1011 | ", |
1013 | 1012 | ); | |
1014 | check_diagnostic(content); | ||
1015 | } | 1013 | } |
1016 | 1014 | ||
1017 | #[test] | 1015 | #[test] |
1018 | fn tuple_of_bools_missing_arms() { | 1016 | fn tuple_of_bools_missing_arms() { |
1019 | let content = r" | 1017 | check_diagnostic( |
1018 | r" | ||
1020 | fn test_fn() { | 1019 | fn test_fn() { |
1021 | match (false, true) { | 1020 | match (false, true) { |
1022 | (true, true) => {}, | 1021 | (true, true) => {}, |
1023 | } | 1022 | } |
1024 | } | 1023 | } |
1025 | "; | 1024 | ", |
1026 | 1025 | ); | |
1027 | check_diagnostic(content); | ||
1028 | } | 1026 | } |
1029 | 1027 | ||
1030 | #[test] | 1028 | #[test] |
1031 | fn tuple_of_bools_missing_arm() { | 1029 | fn tuple_of_bools_missing_arm() { |
1032 | let content = r" | 1030 | check_diagnostic( |
1031 | r" | ||
1033 | fn test_fn() { | 1032 | fn test_fn() { |
1034 | match (false, true) { | 1033 | match (false, true) { |
1035 | (false, true) => {}, | 1034 | (false, true) => {}, |
@@ -1037,14 +1036,14 @@ mod tests { | |||
1037 | (true, false) => {}, | 1036 | (true, false) => {}, |
1038 | } | 1037 | } |
1039 | } | 1038 | } |
1040 | "; | 1039 | ", |
1041 | 1040 | ); | |
1042 | check_diagnostic(content); | ||
1043 | } | 1041 | } |
1044 | 1042 | ||
1045 | #[test] | 1043 | #[test] |
1046 | fn tuple_of_bools_with_wilds() { | 1044 | fn tuple_of_bools_with_wilds() { |
1047 | let content = r" | 1045 | check_no_diagnostic( |
1046 | r" | ||
1048 | fn test_fn() { | 1047 | fn test_fn() { |
1049 | match (false, true) { | 1048 | match (false, true) { |
1050 | (false, _) => {}, | 1049 | (false, _) => {}, |
@@ -1052,14 +1051,14 @@ mod tests { | |||
1052 | (_, true) => {}, | 1051 | (_, true) => {}, |
1053 | } | 1052 | } |
1054 | } | 1053 | } |
1055 | "; | 1054 | ", |
1056 | 1055 | ); | |
1057 | check_no_diagnostic(content); | ||
1058 | } | 1056 | } |
1059 | 1057 | ||
1060 | #[test] | 1058 | #[test] |
1061 | fn tuple_of_bools_no_diagnostic() { | 1059 | fn tuple_of_bools_no_diagnostic() { |
1062 | let content = r" | 1060 | check_no_diagnostic( |
1061 | r" | ||
1063 | fn test_fn() { | 1062 | fn test_fn() { |
1064 | match (false, true) { | 1063 | match (false, true) { |
1065 | (true, true) => {}, | 1064 | (true, true) => {}, |
@@ -1068,27 +1067,27 @@ mod tests { | |||
1068 | (false, false) => {}, | 1067 | (false, false) => {}, |
1069 | } | 1068 | } |
1070 | } | 1069 | } |
1071 | "; | 1070 | ", |
1072 | 1071 | ); | |
1073 | check_no_diagnostic(content); | ||
1074 | } | 1072 | } |
1075 | 1073 | ||
1076 | #[test] | 1074 | #[test] |
1077 | fn tuple_of_bools_binding_missing_arms() { | 1075 | fn tuple_of_bools_binding_missing_arms() { |
1078 | let content = r" | 1076 | check_diagnostic( |
1077 | r" | ||
1079 | fn test_fn() { | 1078 | fn test_fn() { |
1080 | match (false, true) { | 1079 | match (false, true) { |
1081 | (true, _x) => {}, | 1080 | (true, _x) => {}, |
1082 | } | 1081 | } |
1083 | } | 1082 | } |
1084 | "; | 1083 | ", |
1085 | 1084 | ); | |
1086 | check_diagnostic(content); | ||
1087 | } | 1085 | } |
1088 | 1086 | ||
1089 | #[test] | 1087 | #[test] |
1090 | fn tuple_of_bools_binding_no_diagnostic() { | 1088 | fn tuple_of_bools_binding_no_diagnostic() { |
1091 | let content = r" | 1089 | check_no_diagnostic( |
1090 | r" | ||
1092 | fn test_fn() { | 1091 | fn test_fn() { |
1093 | match (false, true) { | 1092 | match (false, true) { |
1094 | (true, _x) => {}, | 1093 | (true, _x) => {}, |
@@ -1096,80 +1095,80 @@ mod tests { | |||
1096 | (false, false) => {}, | 1095 | (false, false) => {}, |
1097 | } | 1096 | } |
1098 | } | 1097 | } |
1099 | "; | 1098 | ", |
1100 | 1099 | ); | |
1101 | check_no_diagnostic(content); | ||
1102 | } | 1100 | } |
1103 | 1101 | ||
1104 | #[test] | 1102 | #[test] |
1105 | fn tuple_of_bools_with_ellipsis_at_end_no_diagnostic() { | 1103 | fn tuple_of_bools_with_ellipsis_at_end_no_diagnostic() { |
1106 | let content = r" | 1104 | check_no_diagnostic( |
1105 | r" | ||
1107 | fn test_fn() { | 1106 | fn test_fn() { |
1108 | match (false, true, false) { | 1107 | match (false, true, false) { |
1109 | (false, ..) => {}, | 1108 | (false, ..) => {}, |
1110 | (true, ..) => {}, | 1109 | (true, ..) => {}, |
1111 | } | 1110 | } |
1112 | } | 1111 | } |
1113 | "; | 1112 | ", |
1114 | 1113 | ); | |
1115 | check_no_diagnostic(content); | ||
1116 | } | 1114 | } |
1117 | 1115 | ||
1118 | #[test] | 1116 | #[test] |
1119 | fn tuple_of_bools_with_ellipsis_at_beginning_no_diagnostic() { | 1117 | fn tuple_of_bools_with_ellipsis_at_beginning_no_diagnostic() { |
1120 | let content = r" | 1118 | check_no_diagnostic( |
1119 | r" | ||
1121 | fn test_fn() { | 1120 | fn test_fn() { |
1122 | match (false, true, false) { | 1121 | match (false, true, false) { |
1123 | (.., false) => {}, | 1122 | (.., false) => {}, |
1124 | (.., true) => {}, | 1123 | (.., true) => {}, |
1125 | } | 1124 | } |
1126 | } | 1125 | } |
1127 | "; | 1126 | ", |
1128 | 1127 | ); | |
1129 | check_no_diagnostic(content); | ||
1130 | } | 1128 | } |
1131 | 1129 | ||
1132 | #[test] | 1130 | #[test] |
1133 | fn tuple_of_bools_with_ellipsis_no_diagnostic() { | 1131 | fn tuple_of_bools_with_ellipsis_no_diagnostic() { |
1134 | let content = r" | 1132 | check_no_diagnostic( |
1133 | r" | ||
1135 | fn test_fn() { | 1134 | fn test_fn() { |
1136 | match (false, true, false) { | 1135 | match (false, true, false) { |
1137 | (..) => {}, | 1136 | (..) => {}, |
1138 | } | 1137 | } |
1139 | } | 1138 | } |
1140 | "; | 1139 | ", |
1141 | 1140 | ); | |
1142 | check_no_diagnostic(content); | ||
1143 | } | 1141 | } |
1144 | 1142 | ||
1145 | #[test] | 1143 | #[test] |
1146 | fn tuple_of_tuple_and_bools_no_arms() { | 1144 | fn tuple_of_tuple_and_bools_no_arms() { |
1147 | let content = r" | 1145 | check_diagnostic( |
1146 | r" | ||
1148 | fn test_fn() { | 1147 | fn test_fn() { |
1149 | match (false, ((), false)) { | 1148 | match (false, ((), false)) { |
1150 | } | 1149 | } |
1151 | } | 1150 | } |
1152 | "; | 1151 | ", |
1153 | 1152 | ); | |
1154 | check_diagnostic(content); | ||
1155 | } | 1153 | } |
1156 | 1154 | ||
1157 | #[test] | 1155 | #[test] |
1158 | fn tuple_of_tuple_and_bools_missing_arms() { | 1156 | fn tuple_of_tuple_and_bools_missing_arms() { |
1159 | let content = r" | 1157 | check_diagnostic( |
1158 | r" | ||
1160 | fn test_fn() { | 1159 | fn test_fn() { |
1161 | match (false, ((), false)) { | 1160 | match (false, ((), false)) { |
1162 | (true, ((), true)) => {}, | 1161 | (true, ((), true)) => {}, |
1163 | } | 1162 | } |
1164 | } | 1163 | } |
1165 | "; | 1164 | ", |
1166 | 1165 | ); | |
1167 | check_diagnostic(content); | ||
1168 | } | 1166 | } |
1169 | 1167 | ||
1170 | #[test] | 1168 | #[test] |
1171 | fn tuple_of_tuple_and_bools_no_diagnostic() { | 1169 | fn tuple_of_tuple_and_bools_no_diagnostic() { |
1172 | let content = r" | 1170 | check_no_diagnostic( |
1171 | r" | ||
1173 | fn test_fn() { | 1172 | fn test_fn() { |
1174 | match (false, ((), false)) { | 1173 | match (false, ((), false)) { |
1175 | (true, ((), true)) => {}, | 1174 | (true, ((), true)) => {}, |
@@ -1178,27 +1177,27 @@ mod tests { | |||
1178 | (false, ((), false)) => {}, | 1177 | (false, ((), false)) => {}, |
1179 | } | 1178 | } |
1180 | } | 1179 | } |
1181 | "; | 1180 | ", |
1182 | 1181 | ); | |
1183 | check_no_diagnostic(content); | ||
1184 | } | 1182 | } |
1185 | 1183 | ||
1186 | #[test] | 1184 | #[test] |
1187 | fn tuple_of_tuple_and_bools_wildcard_missing_arms() { | 1185 | fn tuple_of_tuple_and_bools_wildcard_missing_arms() { |
1188 | let content = r" | 1186 | check_diagnostic( |
1187 | r" | ||
1189 | fn test_fn() { | 1188 | fn test_fn() { |
1190 | match (false, ((), false)) { | 1189 | match (false, ((), false)) { |
1191 | (true, _) => {}, | 1190 | (true, _) => {}, |
1192 | } | 1191 | } |
1193 | } | 1192 | } |
1194 | "; | 1193 | ", |
1195 | 1194 | ); | |
1196 | check_diagnostic(content); | ||
1197 | } | 1195 | } |
1198 | 1196 | ||
1199 | #[test] | 1197 | #[test] |
1200 | fn tuple_of_tuple_and_bools_wildcard_no_diagnostic() { | 1198 | fn tuple_of_tuple_and_bools_wildcard_no_diagnostic() { |
1201 | let content = r" | 1199 | check_no_diagnostic( |
1200 | r" | ||
1202 | fn test_fn() { | 1201 | fn test_fn() { |
1203 | match (false, ((), false)) { | 1202 | match (false, ((), false)) { |
1204 | (true, ((), true)) => {}, | 1203 | (true, ((), true)) => {}, |
@@ -1206,14 +1205,14 @@ mod tests { | |||
1206 | (false, _) => {}, | 1205 | (false, _) => {}, |
1207 | } | 1206 | } |
1208 | } | 1207 | } |
1209 | "; | 1208 | ", |
1210 | 1209 | ); | |
1211 | check_no_diagnostic(content); | ||
1212 | } | 1210 | } |
1213 | 1211 | ||
1214 | #[test] | 1212 | #[test] |
1215 | fn enum_no_arms() { | 1213 | fn enum_no_arms() { |
1216 | let content = r" | 1214 | check_diagnostic( |
1215 | r" | ||
1217 | enum Either { | 1216 | enum Either { |
1218 | A, | 1217 | A, |
1219 | B, | 1218 | B, |
@@ -1222,14 +1221,14 @@ mod tests { | |||
1222 | match Either::A { | 1221 | match Either::A { |
1223 | } | 1222 | } |
1224 | } | 1223 | } |
1225 | "; | 1224 | ", |
1226 | 1225 | ); | |
1227 | check_diagnostic(content); | ||
1228 | } | 1226 | } |
1229 | 1227 | ||
1230 | #[test] | 1228 | #[test] |
1231 | fn enum_missing_arms() { | 1229 | fn enum_missing_arms() { |
1232 | let content = r" | 1230 | check_diagnostic( |
1231 | r" | ||
1233 | enum Either { | 1232 | enum Either { |
1234 | A, | 1233 | A, |
1235 | B, | 1234 | B, |
@@ -1239,14 +1238,14 @@ mod tests { | |||
1239 | Either::A => {}, | 1238 | Either::A => {}, |
1240 | } | 1239 | } |
1241 | } | 1240 | } |
1242 | "; | 1241 | ", |
1243 | 1242 | ); | |
1244 | check_diagnostic(content); | ||
1245 | } | 1243 | } |
1246 | 1244 | ||
1247 | #[test] | 1245 | #[test] |
1248 | fn enum_no_diagnostic() { | 1246 | fn enum_no_diagnostic() { |
1249 | let content = r" | 1247 | check_no_diagnostic( |
1248 | r" | ||
1250 | enum Either { | 1249 | enum Either { |
1251 | A, | 1250 | A, |
1252 | B, | 1251 | B, |
@@ -1257,14 +1256,14 @@ mod tests { | |||
1257 | Either::B => {}, | 1256 | Either::B => {}, |
1258 | } | 1257 | } |
1259 | } | 1258 | } |
1260 | "; | 1259 | ", |
1261 | 1260 | ); | |
1262 | check_no_diagnostic(content); | ||
1263 | } | 1261 | } |
1264 | 1262 | ||
1265 | #[test] | 1263 | #[test] |
1266 | fn enum_ref_missing_arms() { | 1264 | fn enum_ref_missing_arms() { |
1267 | let content = r" | 1265 | check_diagnostic( |
1266 | r" | ||
1268 | enum Either { | 1267 | enum Either { |
1269 | A, | 1268 | A, |
1270 | B, | 1269 | B, |
@@ -1274,14 +1273,14 @@ mod tests { | |||
1274 | Either::A => {}, | 1273 | Either::A => {}, |
1275 | } | 1274 | } |
1276 | } | 1275 | } |
1277 | "; | 1276 | ", |
1278 | 1277 | ); | |
1279 | check_diagnostic(content); | ||
1280 | } | 1278 | } |
1281 | 1279 | ||
1282 | #[test] | 1280 | #[test] |
1283 | fn enum_ref_no_diagnostic() { | 1281 | fn enum_ref_no_diagnostic() { |
1284 | let content = r" | 1282 | check_no_diagnostic( |
1283 | r" | ||
1285 | enum Either { | 1284 | enum Either { |
1286 | A, | 1285 | A, |
1287 | B, | 1286 | B, |
@@ -1292,14 +1291,14 @@ mod tests { | |||
1292 | Either::B => {}, | 1291 | Either::B => {}, |
1293 | } | 1292 | } |
1294 | } | 1293 | } |
1295 | "; | 1294 | ", |
1296 | 1295 | ); | |
1297 | check_no_diagnostic(content); | ||
1298 | } | 1296 | } |
1299 | 1297 | ||
1300 | #[test] | 1298 | #[test] |
1301 | fn enum_containing_bool_no_arms() { | 1299 | fn enum_containing_bool_no_arms() { |
1302 | let content = r" | 1300 | check_diagnostic( |
1301 | r" | ||
1303 | enum Either { | 1302 | enum Either { |
1304 | A(bool), | 1303 | A(bool), |
1305 | B, | 1304 | B, |
@@ -1308,14 +1307,14 @@ mod tests { | |||
1308 | match Either::B { | 1307 | match Either::B { |
1309 | } | 1308 | } |
1310 | } | 1309 | } |
1311 | "; | 1310 | ", |
1312 | 1311 | ); | |
1313 | check_diagnostic(content); | ||
1314 | } | 1312 | } |
1315 | 1313 | ||
1316 | #[test] | 1314 | #[test] |
1317 | fn enum_containing_bool_missing_arms() { | 1315 | fn enum_containing_bool_missing_arms() { |
1318 | let content = r" | 1316 | check_diagnostic( |
1317 | r" | ||
1319 | enum Either { | 1318 | enum Either { |
1320 | A(bool), | 1319 | A(bool), |
1321 | B, | 1320 | B, |
@@ -1326,14 +1325,14 @@ mod tests { | |||
1326 | Either::B => (), | 1325 | Either::B => (), |
1327 | } | 1326 | } |
1328 | } | 1327 | } |
1329 | "; | 1328 | ", |
1330 | 1329 | ); | |
1331 | check_diagnostic(content); | ||
1332 | } | 1330 | } |
1333 | 1331 | ||
1334 | #[test] | 1332 | #[test] |
1335 | fn enum_containing_bool_no_diagnostic() { | 1333 | fn enum_containing_bool_no_diagnostic() { |
1336 | let content = r" | 1334 | check_no_diagnostic( |
1335 | r" | ||
1337 | enum Either { | 1336 | enum Either { |
1338 | A(bool), | 1337 | A(bool), |
1339 | B, | 1338 | B, |
@@ -1345,14 +1344,14 @@ mod tests { | |||
1345 | Either::B => (), | 1344 | Either::B => (), |
1346 | } | 1345 | } |
1347 | } | 1346 | } |
1348 | "; | 1347 | ", |
1349 | 1348 | ); | |
1350 | check_no_diagnostic(content); | ||
1351 | } | 1349 | } |
1352 | 1350 | ||
1353 | #[test] | 1351 | #[test] |
1354 | fn enum_containing_bool_with_wild_no_diagnostic() { | 1352 | fn enum_containing_bool_with_wild_no_diagnostic() { |
1355 | let content = r" | 1353 | check_no_diagnostic( |
1354 | r" | ||
1356 | enum Either { | 1355 | enum Either { |
1357 | A(bool), | 1356 | A(bool), |
1358 | B, | 1357 | B, |
@@ -1363,14 +1362,14 @@ mod tests { | |||
1363 | _ => (), | 1362 | _ => (), |
1364 | } | 1363 | } |
1365 | } | 1364 | } |
1366 | "; | 1365 | ", |
1367 | 1366 | ); | |
1368 | check_no_diagnostic(content); | ||
1369 | } | 1367 | } |
1370 | 1368 | ||
1371 | #[test] | 1369 | #[test] |
1372 | fn enum_containing_bool_with_wild_2_no_diagnostic() { | 1370 | fn enum_containing_bool_with_wild_2_no_diagnostic() { |
1373 | let content = r" | 1371 | check_no_diagnostic( |
1372 | r" | ||
1374 | enum Either { | 1373 | enum Either { |
1375 | A(bool), | 1374 | A(bool), |
1376 | B, | 1375 | B, |
@@ -1381,14 +1380,14 @@ mod tests { | |||
1381 | Either::B => (), | 1380 | Either::B => (), |
1382 | } | 1381 | } |
1383 | } | 1382 | } |
1384 | "; | 1383 | ", |
1385 | 1384 | ); | |
1386 | check_no_diagnostic(content); | ||
1387 | } | 1385 | } |
1388 | 1386 | ||
1389 | #[test] | 1387 | #[test] |
1390 | fn enum_different_sizes_missing_arms() { | 1388 | fn enum_different_sizes_missing_arms() { |
1391 | let content = r" | 1389 | check_diagnostic( |
1390 | r" | ||
1392 | enum Either { | 1391 | enum Either { |
1393 | A(bool), | 1392 | A(bool), |
1394 | B(bool, bool), | 1393 | B(bool, bool), |
@@ -1399,14 +1398,14 @@ mod tests { | |||
1399 | Either::B(false, _) => (), | 1398 | Either::B(false, _) => (), |
1400 | } | 1399 | } |
1401 | } | 1400 | } |
1402 | "; | 1401 | ", |
1403 | 1402 | ); | |
1404 | check_diagnostic(content); | ||
1405 | } | 1403 | } |
1406 | 1404 | ||
1407 | #[test] | 1405 | #[test] |
1408 | fn enum_different_sizes_no_diagnostic() { | 1406 | fn enum_different_sizes_no_diagnostic() { |
1409 | let content = r" | 1407 | check_no_diagnostic( |
1408 | r" | ||
1410 | enum Either { | 1409 | enum Either { |
1411 | A(bool), | 1410 | A(bool), |
1412 | B(bool, bool), | 1411 | B(bool, bool), |
@@ -1418,14 +1417,14 @@ mod tests { | |||
1418 | Either::B(false, _) => (), | 1417 | Either::B(false, _) => (), |
1419 | } | 1418 | } |
1420 | } | 1419 | } |
1421 | "; | 1420 | ", |
1422 | 1421 | ); | |
1423 | check_no_diagnostic(content); | ||
1424 | } | 1422 | } |
1425 | 1423 | ||
1426 | #[test] | 1424 | #[test] |
1427 | fn or_no_diagnostic() { | 1425 | fn or_no_diagnostic() { |
1428 | let content = r" | 1426 | check_no_diagnostic( |
1427 | r" | ||
1429 | enum Either { | 1428 | enum Either { |
1430 | A(bool), | 1429 | A(bool), |
1431 | B(bool, bool), | 1430 | B(bool, bool), |
@@ -1437,14 +1436,14 @@ mod tests { | |||
1437 | Either::B(false, _) => (), | 1436 | Either::B(false, _) => (), |
1438 | } | 1437 | } |
1439 | } | 1438 | } |
1440 | "; | 1439 | ", |
1441 | 1440 | ); | |
1442 | check_no_diagnostic(content); | ||
1443 | } | 1441 | } |
1444 | 1442 | ||
1445 | #[test] | 1443 | #[test] |
1446 | fn tuple_of_enum_no_diagnostic() { | 1444 | fn tuple_of_enum_no_diagnostic() { |
1447 | let content = r" | 1445 | check_no_diagnostic( |
1446 | r" | ||
1448 | enum Either { | 1447 | enum Either { |
1449 | A(bool), | 1448 | A(bool), |
1450 | B(bool, bool), | 1449 | B(bool, bool), |
@@ -1461,14 +1460,16 @@ mod tests { | |||
1461 | (Either::B(_, _), Either2::D) => (), | 1460 | (Either::B(_, _), Either2::D) => (), |
1462 | } | 1461 | } |
1463 | } | 1462 | } |
1464 | "; | 1463 | ", |
1465 | 1464 | ); | |
1466 | check_no_diagnostic(content); | ||
1467 | } | 1465 | } |
1468 | 1466 | ||
1469 | #[test] | 1467 | #[test] |
1470 | fn mismatched_types() { | 1468 | fn mismatched_types() { |
1471 | let content = r" | 1469 | // Match statements with arms that don't match the |
1470 | // expression pattern do not fire this diagnostic. | ||
1471 | check_no_diagnostic( | ||
1472 | r" | ||
1472 | enum Either { | 1473 | enum Either { |
1473 | A, | 1474 | A, |
1474 | B, | 1475 | B, |
@@ -1483,47 +1484,47 @@ mod tests { | |||
1483 | Either2::D => (), | 1484 | Either2::D => (), |
1484 | } | 1485 | } |
1485 | } | 1486 | } |
1486 | "; | 1487 | ", |
1487 | 1488 | ); | |
1488 | // Match statements with arms that don't match the | ||
1489 | // expression pattern do not fire this diagnostic. | ||
1490 | check_no_diagnostic(content); | ||
1491 | } | 1489 | } |
1492 | 1490 | ||
1493 | #[test] | 1491 | #[test] |
1494 | fn mismatched_types_with_different_arity() { | 1492 | fn mismatched_types_with_different_arity() { |
1495 | let content = r" | 1493 | // Match statements with arms that don't match the |
1494 | // expression pattern do not fire this diagnostic. | ||
1495 | check_no_diagnostic( | ||
1496 | r" | ||
1496 | fn test_fn() { | 1497 | fn test_fn() { |
1497 | match (true, false) { | 1498 | match (true, false) { |
1498 | (true, false, true) => (), | 1499 | (true, false, true) => (), |
1499 | (true) => (), | 1500 | (true) => (), |
1500 | } | 1501 | } |
1501 | } | 1502 | } |
1502 | "; | 1503 | ", |
1503 | 1504 | ); | |
1504 | // Match statements with arms that don't match the | ||
1505 | // expression pattern do not fire this diagnostic. | ||
1506 | check_no_diagnostic(content); | ||
1507 | } | 1505 | } |
1508 | 1506 | ||
1509 | #[test] | 1507 | #[test] |
1510 | fn malformed_match_arm_tuple_missing_pattern() { | 1508 | fn malformed_match_arm_tuple_missing_pattern() { |
1511 | let content = r" | 1509 | // Match statements with arms that don't match the |
1510 | // expression pattern do not fire this diagnostic. | ||
1511 | check_no_diagnostic( | ||
1512 | r" | ||
1512 | fn test_fn() { | 1513 | fn test_fn() { |
1513 | match (0) { | 1514 | match (0) { |
1514 | () => (), | 1515 | () => (), |
1515 | } | 1516 | } |
1516 | } | 1517 | } |
1517 | "; | 1518 | ", |
1518 | 1519 | ); | |
1519 | // Match statements with arms that don't match the | ||
1520 | // expression pattern do not fire this diagnostic. | ||
1521 | check_no_diagnostic(content); | ||
1522 | } | 1520 | } |
1523 | 1521 | ||
1524 | #[test] | 1522 | #[test] |
1525 | fn malformed_match_arm_tuple_enum_missing_pattern() { | 1523 | fn malformed_match_arm_tuple_enum_missing_pattern() { |
1526 | let content = r" | 1524 | // We are testing to be sure we don't panic here when the match |
1525 | // arm `Either::B` is missing its pattern. | ||
1526 | check_no_diagnostic( | ||
1527 | r" | ||
1527 | enum Either { | 1528 | enum Either { |
1528 | A, | 1529 | A, |
1529 | B(u32), | 1530 | B(u32), |
@@ -1534,32 +1535,30 @@ mod tests { | |||
1534 | Either::B() => (), | 1535 | Either::B() => (), |
1535 | } | 1536 | } |
1536 | } | 1537 | } |
1537 | "; | 1538 | ", |
1538 | 1539 | ); | |
1539 | // We are testing to be sure we don't panic here when the match | ||
1540 | // arm `Either::B` is missing its pattern. | ||
1541 | check_no_diagnostic(content); | ||
1542 | } | 1540 | } |
1543 | 1541 | ||
1544 | #[test] | 1542 | #[test] |
1545 | fn enum_not_in_scope() { | 1543 | fn enum_not_in_scope() { |
1546 | let content = r" | 1544 | // The enum is not in scope so we don't perform exhaustiveness |
1545 | // checking, but we want to be sure we don't panic here (and | ||
1546 | // we don't create a diagnostic). | ||
1547 | check_no_diagnostic( | ||
1548 | r" | ||
1547 | fn test_fn() { | 1549 | fn test_fn() { |
1548 | match Foo::Bar { | 1550 | match Foo::Bar { |
1549 | Foo::Baz => (), | 1551 | Foo::Baz => (), |
1550 | } | 1552 | } |
1551 | } | 1553 | } |
1552 | "; | 1554 | ", |
1553 | 1555 | ); | |
1554 | // The enum is not in scope so we don't perform exhaustiveness | ||
1555 | // checking, but we want to be sure we don't panic here (and | ||
1556 | // we don't create a diagnostic). | ||
1557 | check_no_diagnostic(content); | ||
1558 | } | 1556 | } |
1559 | 1557 | ||
1560 | #[test] | 1558 | #[test] |
1561 | fn expr_diverges() { | 1559 | fn expr_diverges() { |
1562 | let content = r" | 1560 | check_no_diagnostic( |
1561 | r" | ||
1563 | enum Either { | 1562 | enum Either { |
1564 | A, | 1563 | A, |
1565 | B, | 1564 | B, |
@@ -1570,14 +1569,14 @@ mod tests { | |||
1570 | Either::B => (), | 1569 | Either::B => (), |
1571 | } | 1570 | } |
1572 | } | 1571 | } |
1573 | "; | 1572 | ", |
1574 | 1573 | ); | |
1575 | check_no_diagnostic(content); | ||
1576 | } | 1574 | } |
1577 | 1575 | ||
1578 | #[test] | 1576 | #[test] |
1579 | fn expr_loop_with_break() { | 1577 | fn expr_loop_with_break() { |
1580 | let content = r" | 1578 | check_no_diagnostic( |
1579 | r" | ||
1581 | enum Either { | 1580 | enum Either { |
1582 | A, | 1581 | A, |
1583 | B, | 1582 | B, |
@@ -1588,14 +1587,14 @@ mod tests { | |||
1588 | Either::B => (), | 1587 | Either::B => (), |
1589 | } | 1588 | } |
1590 | } | 1589 | } |
1591 | "; | 1590 | ", |
1592 | 1591 | ); | |
1593 | check_no_diagnostic(content); | ||
1594 | } | 1592 | } |
1595 | 1593 | ||
1596 | #[test] | 1594 | #[test] |
1597 | fn expr_partially_diverges() { | 1595 | fn expr_partially_diverges() { |
1598 | let content = r" | 1596 | check_no_diagnostic( |
1597 | r" | ||
1599 | enum Either<T> { | 1598 | enum Either<T> { |
1600 | A(T), | 1599 | A(T), |
1601 | B, | 1600 | B, |
@@ -1609,14 +1608,14 @@ mod tests { | |||
1609 | Either::B => 0, | 1608 | Either::B => 0, |
1610 | } | 1609 | } |
1611 | } | 1610 | } |
1612 | "; | 1611 | ", |
1613 | 1612 | ); | |
1614 | check_no_diagnostic(content); | ||
1615 | } | 1613 | } |
1616 | 1614 | ||
1617 | #[test] | 1615 | #[test] |
1618 | fn enum_record_no_arms() { | 1616 | fn enum_record_no_arms() { |
1619 | let content = r" | 1617 | check_diagnostic( |
1618 | r" | ||
1620 | enum Either { | 1619 | enum Either { |
1621 | A { foo: bool }, | 1620 | A { foo: bool }, |
1622 | B, | 1621 | B, |
@@ -1626,14 +1625,14 @@ mod tests { | |||
1626 | match a { | 1625 | match a { |
1627 | } | 1626 | } |
1628 | } | 1627 | } |
1629 | "; | 1628 | ", |
1630 | 1629 | ); | |
1631 | check_diagnostic(content); | ||
1632 | } | 1630 | } |
1633 | 1631 | ||
1634 | #[test] | 1632 | #[test] |
1635 | fn enum_record_missing_arms() { | 1633 | fn enum_record_missing_arms() { |
1636 | let content = r" | 1634 | check_diagnostic( |
1635 | r" | ||
1637 | enum Either { | 1636 | enum Either { |
1638 | A { foo: bool }, | 1637 | A { foo: bool }, |
1639 | B, | 1638 | B, |
@@ -1644,14 +1643,14 @@ mod tests { | |||
1644 | Either::A { foo: true } => (), | 1643 | Either::A { foo: true } => (), |
1645 | } | 1644 | } |
1646 | } | 1645 | } |
1647 | "; | 1646 | ", |
1648 | 1647 | ); | |
1649 | check_diagnostic(content); | ||
1650 | } | 1648 | } |
1651 | 1649 | ||
1652 | #[test] | 1650 | #[test] |
1653 | fn enum_record_no_diagnostic() { | 1651 | fn enum_record_no_diagnostic() { |
1654 | let content = r" | 1652 | check_no_diagnostic( |
1653 | r" | ||
1655 | enum Either { | 1654 | enum Either { |
1656 | A { foo: bool }, | 1655 | A { foo: bool }, |
1657 | B, | 1656 | B, |
@@ -1664,14 +1663,17 @@ mod tests { | |||
1664 | Either::B => (), | 1663 | Either::B => (), |
1665 | } | 1664 | } |
1666 | } | 1665 | } |
1667 | "; | 1666 | ", |
1668 | 1667 | ); | |
1669 | check_no_diagnostic(content); | ||
1670 | } | 1668 | } |
1671 | 1669 | ||
1672 | #[test] | 1670 | #[test] |
1673 | fn enum_record_missing_field_no_diagnostic() { | 1671 | fn enum_record_missing_field_no_diagnostic() { |
1674 | let content = r" | 1672 | // When `Either::A` is missing a struct member, we don't want |
1673 | // to fire the missing match arm diagnostic. This should fire | ||
1674 | // some other diagnostic. | ||
1675 | check_no_diagnostic( | ||
1676 | r" | ||
1675 | enum Either { | 1677 | enum Either { |
1676 | A { foo: bool }, | 1678 | A { foo: bool }, |
1677 | B, | 1679 | B, |
@@ -1683,17 +1685,16 @@ mod tests { | |||
1683 | Either::B => (), | 1685 | Either::B => (), |
1684 | } | 1686 | } |
1685 | } | 1687 | } |
1686 | "; | 1688 | ", |
1687 | 1689 | ); | |
1688 | // When `Either::A` is missing a struct member, we don't want | ||
1689 | // to fire the missing match arm diagnostic. This should fire | ||
1690 | // some other diagnostic. | ||
1691 | check_no_diagnostic(content); | ||
1692 | } | 1690 | } |
1693 | 1691 | ||
1694 | #[test] | 1692 | #[test] |
1695 | fn enum_record_missing_field_missing_match_arm() { | 1693 | fn enum_record_missing_field_missing_match_arm() { |
1696 | let content = r" | 1694 | // Even though `Either::A` is missing fields, we still want to fire |
1695 | // the missing arm diagnostic here, since we know `Either::B` is missing. | ||
1696 | check_diagnostic( | ||
1697 | r" | ||
1697 | enum Either { | 1698 | enum Either { |
1698 | A { foo: bool }, | 1699 | A { foo: bool }, |
1699 | B, | 1700 | B, |
@@ -1704,16 +1705,14 @@ mod tests { | |||
1704 | Either::A { } => (), | 1705 | Either::A { } => (), |
1705 | } | 1706 | } |
1706 | } | 1707 | } |
1707 | "; | 1708 | ", |
1708 | 1709 | ); | |
1709 | // Even though `Either::A` is missing fields, we still want to fire | ||
1710 | // the missing arm diagnostic here, since we know `Either::B` is missing. | ||
1711 | check_diagnostic(content); | ||
1712 | } | 1710 | } |
1713 | 1711 | ||
1714 | #[test] | 1712 | #[test] |
1715 | fn enum_record_no_diagnostic_wild() { | 1713 | fn enum_record_no_diagnostic_wild() { |
1716 | let content = r" | 1714 | check_no_diagnostic( |
1715 | r" | ||
1717 | enum Either { | 1716 | enum Either { |
1718 | A { foo: bool }, | 1717 | A { foo: bool }, |
1719 | B, | 1718 | B, |
@@ -1725,14 +1724,14 @@ mod tests { | |||
1725 | Either::B => (), | 1724 | Either::B => (), |
1726 | } | 1725 | } |
1727 | } | 1726 | } |
1728 | "; | 1727 | ", |
1729 | 1728 | ); | |
1730 | check_no_diagnostic(content); | ||
1731 | } | 1729 | } |
1732 | 1730 | ||
1733 | #[test] | 1731 | #[test] |
1734 | fn enum_record_fields_out_of_order_missing_arm() { | 1732 | fn enum_record_fields_out_of_order_missing_arm() { |
1735 | let content = r" | 1733 | check_diagnostic( |
1734 | r" | ||
1736 | enum Either { | 1735 | enum Either { |
1737 | A { foo: bool, bar: () }, | 1736 | A { foo: bool, bar: () }, |
1738 | B, | 1737 | B, |
@@ -1744,14 +1743,14 @@ mod tests { | |||
1744 | Either::A { foo: true, bar: () } => (), | 1743 | Either::A { foo: true, bar: () } => (), |
1745 | } | 1744 | } |
1746 | } | 1745 | } |
1747 | "; | 1746 | ", |
1748 | 1747 | ); | |
1749 | check_diagnostic(content); | ||
1750 | } | 1748 | } |
1751 | 1749 | ||
1752 | #[test] | 1750 | #[test] |
1753 | fn enum_record_fields_out_of_order_no_diagnostic() { | 1751 | fn enum_record_fields_out_of_order_no_diagnostic() { |
1754 | let content = r" | 1752 | check_no_diagnostic( |
1753 | r" | ||
1755 | enum Either { | 1754 | enum Either { |
1756 | A { foo: bool, bar: () }, | 1755 | A { foo: bool, bar: () }, |
1757 | B, | 1756 | B, |
@@ -1764,89 +1763,89 @@ mod tests { | |||
1764 | Either::B => (), | 1763 | Either::B => (), |
1765 | } | 1764 | } |
1766 | } | 1765 | } |
1767 | "; | 1766 | ", |
1768 | 1767 | ); | |
1769 | check_no_diagnostic(content); | ||
1770 | } | 1768 | } |
1771 | 1769 | ||
1772 | #[test] | 1770 | #[test] |
1773 | fn enum_record_ellipsis_missing_arm() { | 1771 | fn enum_record_ellipsis_missing_arm() { |
1774 | let content = r" | 1772 | check_diagnostic( |
1775 | enum Either { | 1773 | r" |
1776 | A { foo: bool, bar: bool }, | 1774 | enum Either { |
1777 | B, | 1775 | A { foo: bool, bar: bool }, |
1778 | } | 1776 | B, |
1779 | fn test_fn() { | 1777 | } |
1780 | match Either::B { | 1778 | fn test_fn() { |
1781 | Either::A { foo: true, .. } => (), | 1779 | match Either::B { |
1782 | Either::B => (), | 1780 | Either::A { foo: true, .. } => (), |
1783 | } | 1781 | Either::B => (), |
1784 | } | 1782 | } |
1785 | "; | 1783 | } |
1786 | 1784 | ", | |
1787 | check_diagnostic(content); | 1785 | ); |
1788 | } | 1786 | } |
1789 | 1787 | ||
1790 | #[test] | 1788 | #[test] |
1791 | fn enum_record_ellipsis_no_diagnostic() { | 1789 | fn enum_record_ellipsis_no_diagnostic() { |
1792 | let content = r" | 1790 | check_no_diagnostic( |
1793 | enum Either { | 1791 | r" |
1794 | A { foo: bool, bar: bool }, | 1792 | enum Either { |
1795 | B, | 1793 | A { foo: bool, bar: bool }, |
1796 | } | 1794 | B, |
1797 | fn test_fn() { | 1795 | } |
1798 | let a = Either::A { foo: true }; | 1796 | fn test_fn() { |
1799 | match a { | 1797 | let a = Either::A { foo: true }; |
1800 | Either::A { foo: true, .. } => (), | 1798 | match a { |
1801 | Either::A { foo: false, .. } => (), | 1799 | Either::A { foo: true, .. } => (), |
1802 | Either::B => (), | 1800 | Either::A { foo: false, .. } => (), |
1803 | } | 1801 | Either::B => (), |
1804 | } | 1802 | } |
1805 | "; | 1803 | } |
1806 | 1804 | ", | |
1807 | check_no_diagnostic(content); | 1805 | ); |
1808 | } | 1806 | } |
1809 | 1807 | ||
1810 | #[test] | 1808 | #[test] |
1811 | fn enum_record_ellipsis_all_fields_missing_arm() { | 1809 | fn enum_record_ellipsis_all_fields_missing_arm() { |
1812 | let content = r" | 1810 | check_diagnostic( |
1813 | enum Either { | 1811 | r" |
1814 | A { foo: bool, bar: bool }, | 1812 | enum Either { |
1815 | B, | 1813 | A { foo: bool, bar: bool }, |
1816 | } | 1814 | B, |
1817 | fn test_fn() { | 1815 | } |
1818 | let a = Either::B; | 1816 | fn test_fn() { |
1819 | match a { | 1817 | let a = Either::B; |
1820 | Either::A { .. } => (), | 1818 | match a { |
1821 | } | 1819 | Either::A { .. } => (), |
1822 | } | 1820 | } |
1823 | "; | 1821 | } |
1824 | 1822 | ", | |
1825 | check_diagnostic(content); | 1823 | ); |
1826 | } | 1824 | } |
1827 | 1825 | ||
1828 | #[test] | 1826 | #[test] |
1829 | fn enum_record_ellipsis_all_fields_no_diagnostic() { | 1827 | fn enum_record_ellipsis_all_fields_no_diagnostic() { |
1830 | let content = r" | 1828 | check_no_diagnostic( |
1831 | enum Either { | 1829 | r" |
1832 | A { foo: bool, bar: bool }, | 1830 | enum Either { |
1833 | B, | 1831 | A { foo: bool, bar: bool }, |
1834 | } | 1832 | B, |
1835 | fn test_fn() { | 1833 | } |
1836 | let a = Either::B; | 1834 | fn test_fn() { |
1837 | match a { | 1835 | let a = Either::B; |
1838 | Either::A { .. } => (), | 1836 | match a { |
1839 | Either::B => (), | 1837 | Either::A { .. } => (), |
1840 | } | 1838 | Either::B => (), |
1841 | } | 1839 | } |
1842 | "; | 1840 | } |
1843 | 1841 | ", | |
1844 | check_no_diagnostic(content); | 1842 | ); |
1845 | } | 1843 | } |
1846 | 1844 | ||
1847 | #[test] | 1845 | #[test] |
1848 | fn enum_tuple_partial_ellipsis_no_diagnostic() { | 1846 | fn enum_tuple_partial_ellipsis_no_diagnostic() { |
1849 | let content = r" | 1847 | check_no_diagnostic( |
1848 | r" | ||
1850 | enum Either { | 1849 | enum Either { |
1851 | A(bool, bool, bool, bool), | 1850 | A(bool, bool, bool, bool), |
1852 | B, | 1851 | B, |
@@ -1860,14 +1859,14 @@ mod tests { | |||
1860 | Either::B => {}, | 1859 | Either::B => {}, |
1861 | } | 1860 | } |
1862 | } | 1861 | } |
1863 | "; | 1862 | ", |
1864 | 1863 | ); | |
1865 | check_no_diagnostic(content); | ||
1866 | } | 1864 | } |
1867 | 1865 | ||
1868 | #[test] | 1866 | #[test] |
1869 | fn enum_tuple_partial_ellipsis_2_no_diagnostic() { | 1867 | fn enum_tuple_partial_ellipsis_2_no_diagnostic() { |
1870 | let content = r" | 1868 | check_no_diagnostic( |
1869 | r" | ||
1871 | enum Either { | 1870 | enum Either { |
1872 | A(bool, bool, bool, bool), | 1871 | A(bool, bool, bool, bool), |
1873 | B, | 1872 | B, |
@@ -1881,14 +1880,14 @@ mod tests { | |||
1881 | Either::B => {}, | 1880 | Either::B => {}, |
1882 | } | 1881 | } |
1883 | } | 1882 | } |
1884 | "; | 1883 | ", |
1885 | 1884 | ); | |
1886 | check_no_diagnostic(content); | ||
1887 | } | 1885 | } |
1888 | 1886 | ||
1889 | #[test] | 1887 | #[test] |
1890 | fn enum_tuple_partial_ellipsis_missing_arm() { | 1888 | fn enum_tuple_partial_ellipsis_missing_arm() { |
1891 | let content = r" | 1889 | check_diagnostic( |
1890 | r" | ||
1892 | enum Either { | 1891 | enum Either { |
1893 | A(bool, bool, bool, bool), | 1892 | A(bool, bool, bool, bool), |
1894 | B, | 1893 | B, |
@@ -1901,14 +1900,14 @@ mod tests { | |||
1901 | Either::B => {}, | 1900 | Either::B => {}, |
1902 | } | 1901 | } |
1903 | } | 1902 | } |
1904 | "; | 1903 | ", |
1905 | 1904 | ); | |
1906 | check_diagnostic(content); | ||
1907 | } | 1905 | } |
1908 | 1906 | ||
1909 | #[test] | 1907 | #[test] |
1910 | fn enum_tuple_partial_ellipsis_2_missing_arm() { | 1908 | fn enum_tuple_partial_ellipsis_2_missing_arm() { |
1911 | let content = r" | 1909 | check_diagnostic( |
1910 | r" | ||
1912 | enum Either { | 1911 | enum Either { |
1913 | A(bool, bool, bool, bool), | 1912 | A(bool, bool, bool, bool), |
1914 | B, | 1913 | B, |
@@ -1921,14 +1920,14 @@ mod tests { | |||
1921 | Either::B => {}, | 1920 | Either::B => {}, |
1922 | } | 1921 | } |
1923 | } | 1922 | } |
1924 | "; | 1923 | ", |
1925 | 1924 | ); | |
1926 | check_diagnostic(content); | ||
1927 | } | 1925 | } |
1928 | 1926 | ||
1929 | #[test] | 1927 | #[test] |
1930 | fn enum_tuple_ellipsis_no_diagnostic() { | 1928 | fn enum_tuple_ellipsis_no_diagnostic() { |
1931 | let content = r" | 1929 | check_no_diagnostic( |
1930 | r" | ||
1932 | enum Either { | 1931 | enum Either { |
1933 | A(bool, bool, bool, bool), | 1932 | A(bool, bool, bool, bool), |
1934 | B, | 1933 | B, |
@@ -1939,51 +1938,51 @@ mod tests { | |||
1939 | Either::B => {}, | 1938 | Either::B => {}, |
1940 | } | 1939 | } |
1941 | } | 1940 | } |
1942 | "; | 1941 | ", |
1943 | 1942 | ); | |
1944 | check_no_diagnostic(content); | ||
1945 | } | 1943 | } |
1946 | 1944 | ||
1947 | #[test] | 1945 | #[test] |
1948 | fn enum_never() { | 1946 | fn enum_never() { |
1949 | let content = r" | 1947 | check_no_diagnostic( |
1948 | r" | ||
1950 | enum Never {} | 1949 | enum Never {} |
1951 | 1950 | ||
1952 | fn test_fn(never: Never) { | 1951 | fn test_fn(never: Never) { |
1953 | match never {} | 1952 | match never {} |
1954 | } | 1953 | } |
1955 | "; | 1954 | ", |
1956 | 1955 | ); | |
1957 | check_no_diagnostic(content); | ||
1958 | } | 1956 | } |
1959 | 1957 | ||
1960 | #[test] | 1958 | #[test] |
1961 | fn type_never() { | 1959 | fn type_never() { |
1962 | let content = r" | 1960 | check_no_diagnostic( |
1961 | r" | ||
1963 | fn test_fn(never: !) { | 1962 | fn test_fn(never: !) { |
1964 | match never {} | 1963 | match never {} |
1965 | } | 1964 | } |
1966 | "; | 1965 | ", |
1967 | 1966 | ); | |
1968 | check_no_diagnostic(content); | ||
1969 | } | 1967 | } |
1970 | 1968 | ||
1971 | #[test] | 1969 | #[test] |
1972 | fn enum_never_ref() { | 1970 | fn enum_never_ref() { |
1973 | let content = r" | 1971 | check_no_diagnostic( |
1972 | r" | ||
1974 | enum Never {} | 1973 | enum Never {} |
1975 | 1974 | ||
1976 | fn test_fn(never: &Never) { | 1975 | fn test_fn(never: &Never) { |
1977 | match never {} | 1976 | match never {} |
1978 | } | 1977 | } |
1979 | "; | 1978 | ", |
1980 | 1979 | ); | |
1981 | check_no_diagnostic(content); | ||
1982 | } | 1980 | } |
1983 | 1981 | ||
1984 | #[test] | 1982 | #[test] |
1985 | fn expr_diverges_missing_arm() { | 1983 | fn expr_diverges_missing_arm() { |
1986 | let content = r" | 1984 | check_no_diagnostic( |
1985 | r" | ||
1987 | enum Either { | 1986 | enum Either { |
1988 | A, | 1987 | A, |
1989 | B, | 1988 | B, |
@@ -1993,14 +1992,14 @@ mod tests { | |||
1993 | Either::A => (), | 1992 | Either::A => (), |
1994 | } | 1993 | } |
1995 | } | 1994 | } |
1996 | "; | 1995 | ", |
1997 | 1996 | ); | |
1998 | check_no_diagnostic(content); | ||
1999 | } | 1997 | } |
2000 | 1998 | ||
2001 | #[test] | 1999 | #[test] |
2002 | fn or_pattern_panic() { | 2000 | fn or_pattern_panic() { |
2003 | let content = r" | 2001 | check_no_diagnostic( |
2002 | r" | ||
2004 | pub enum Category { | 2003 | pub enum Category { |
2005 | Infinity, | 2004 | Infinity, |
2006 | Zero, | 2005 | Zero, |
@@ -2012,9 +2011,8 @@ mod tests { | |||
2012 | (_, Category::Zero | Category::Infinity) => {} | 2011 | (_, Category::Zero | Category::Infinity) => {} |
2013 | } | 2012 | } |
2014 | } | 2013 | } |
2015 | "; | 2014 | ", |
2016 | 2015 | ); | |
2017 | check_no_diagnostic(content); | ||
2018 | } | 2016 | } |
2019 | } | 2017 | } |
2020 | 2018 | ||
@@ -2034,23 +2032,26 @@ mod false_negatives { | |||
2034 | 2032 | ||
2035 | #[test] | 2033 | #[test] |
2036 | fn integers() { | 2034 | fn integers() { |
2037 | let content = r" | 2035 | // This is a false negative. |
2036 | // We don't currently check integer exhaustiveness. | ||
2037 | check_no_diagnostic( | ||
2038 | r" | ||
2038 | fn test_fn() { | 2039 | fn test_fn() { |
2039 | match 5 { | 2040 | match 5 { |
2040 | 10 => (), | 2041 | 10 => (), |
2041 | 11..20 => (), | 2042 | 11..20 => (), |
2042 | } | 2043 | } |
2043 | } | 2044 | } |
2044 | "; | 2045 | ", |
2045 | 2046 | ); | |
2046 | // This is a false negative. | ||
2047 | // We don't currently check integer exhaustiveness. | ||
2048 | check_no_diagnostic(content); | ||
2049 | } | 2047 | } |
2050 | 2048 | ||
2051 | #[test] | 2049 | #[test] |
2052 | fn internal_or() { | 2050 | fn internal_or() { |
2053 | let content = r" | 2051 | // This is a false negative. |
2052 | // We do not currently handle patterns with internal `or`s. | ||
2053 | check_no_diagnostic( | ||
2054 | r" | ||
2054 | fn test_fn() { | 2055 | fn test_fn() { |
2055 | enum Either { | 2056 | enum Either { |
2056 | A(bool), | 2057 | A(bool), |
@@ -2060,16 +2061,18 @@ mod false_negatives { | |||
2060 | Either::A(true | false) => (), | 2061 | Either::A(true | false) => (), |
2061 | } | 2062 | } |
2062 | } | 2063 | } |
2063 | "; | 2064 | ", |
2064 | 2065 | ); | |
2065 | // This is a false negative. | ||
2066 | // We do not currently handle patterns with internal `or`s. | ||
2067 | check_no_diagnostic(content); | ||
2068 | } | 2066 | } |
2069 | 2067 | ||
2070 | #[test] | 2068 | #[test] |
2071 | fn expr_loop_missing_arm() { | 2069 | fn expr_loop_missing_arm() { |
2072 | let content = r" | 2070 | // This is a false negative. |
2071 | // We currently infer the type of `loop { break Foo::A }` to `!`, which | ||
2072 | // causes us to skip the diagnostic since `Either::A` doesn't type check | ||
2073 | // with `!`. | ||
2074 | check_diagnostic( | ||
2075 | r" | ||
2073 | enum Either { | 2076 | enum Either { |
2074 | A, | 2077 | A, |
2075 | B, | 2078 | B, |
@@ -2079,48 +2082,46 @@ mod false_negatives { | |||
2079 | Either::A => (), | 2082 | Either::A => (), |
2080 | } | 2083 | } |
2081 | } | 2084 | } |
2082 | "; | 2085 | ", |
2083 | 2086 | ); | |
2084 | // This is a false negative. | ||
2085 | // We currently infer the type of `loop { break Foo::A }` to `!`, which | ||
2086 | // causes us to skip the diagnostic since `Either::A` doesn't type check | ||
2087 | // with `!`. | ||
2088 | check_diagnostic(content); | ||
2089 | } | 2087 | } |
2090 | 2088 | ||
2091 | #[test] | 2089 | #[test] |
2092 | fn tuple_of_bools_with_ellipsis_at_end_missing_arm() { | 2090 | fn tuple_of_bools_with_ellipsis_at_end_missing_arm() { |
2093 | let content = r" | 2091 | // This is a false negative. |
2092 | // We don't currently handle tuple patterns with ellipsis. | ||
2093 | check_no_diagnostic( | ||
2094 | r" | ||
2094 | fn test_fn() { | 2095 | fn test_fn() { |
2095 | match (false, true, false) { | 2096 | match (false, true, false) { |
2096 | (false, ..) => {}, | 2097 | (false, ..) => {}, |
2097 | } | 2098 | } |
2098 | } | 2099 | } |
2099 | "; | 2100 | ", |
2100 | 2101 | ); | |
2101 | // This is a false negative. | ||
2102 | // We don't currently handle tuple patterns with ellipsis. | ||
2103 | check_no_diagnostic(content); | ||
2104 | } | 2102 | } |
2105 | 2103 | ||
2106 | #[test] | 2104 | #[test] |
2107 | fn tuple_of_bools_with_ellipsis_at_beginning_missing_arm() { | 2105 | fn tuple_of_bools_with_ellipsis_at_beginning_missing_arm() { |
2108 | let content = r" | 2106 | // This is a false negative. |
2107 | // We don't currently handle tuple patterns with ellipsis. | ||
2108 | check_no_diagnostic( | ||
2109 | r" | ||
2109 | fn test_fn() { | 2110 | fn test_fn() { |
2110 | match (false, true, false) { | 2111 | match (false, true, false) { |
2111 | (.., false) => {}, | 2112 | (.., false) => {}, |
2112 | } | 2113 | } |
2113 | } | 2114 | } |
2114 | "; | 2115 | ", |
2115 | 2116 | ); | |
2116 | // This is a false negative. | ||
2117 | // We don't currently handle tuple patterns with ellipsis. | ||
2118 | check_no_diagnostic(content); | ||
2119 | } | 2117 | } |
2120 | 2118 | ||
2121 | #[test] | 2119 | #[test] |
2122 | fn struct_missing_arm() { | 2120 | fn struct_missing_arm() { |
2123 | let content = r" | 2121 | // This is a false negative. |
2122 | // We don't currently handle structs. | ||
2123 | check_no_diagnostic( | ||
2124 | r" | ||
2124 | struct Foo { | 2125 | struct Foo { |
2125 | a: bool, | 2126 | a: bool, |
2126 | } | 2127 | } |
@@ -2129,10 +2130,7 @@ mod false_negatives { | |||
2129 | Foo { a: true } => {}, | 2130 | Foo { a: true } => {}, |
2130 | } | 2131 | } |
2131 | } | 2132 | } |
2132 | "; | 2133 | ", |
2133 | 2134 | ); | |
2134 | // This is a false negative. | ||
2135 | // We don't currently handle structs. | ||
2136 | check_no_diagnostic(content); | ||
2137 | } | 2135 | } |
2138 | } | 2136 | } |