diff options
author | Dawer <[email protected]> | 2021-05-12 08:50:22 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:49:44 +0100 |
commit | 977ba46bb113c9e9ec159f01a72f51a0a7b92c1b (patch) | |
tree | 32180c33ddfc3ebcec23fe741fe9bad48a0e5aa8 /crates/hir_ty/src | |
parent | 4cce7a6407821f456741a8d512ae31da3128c84f (diff) |
Test match guards, reference patterns
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/diagnostics/match_check.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 061ef754d..5fb98ff35 100644 --- a/crates/hir_ty/src/diagnostics/match_check.rs +++ b/crates/hir_ty/src/diagnostics/match_check.rs | |||
@@ -1126,6 +1126,25 @@ fn main() { | |||
1126 | ); | 1126 | ); |
1127 | } | 1127 | } |
1128 | 1128 | ||
1129 | #[test] | ||
1130 | fn match_guard() { | ||
1131 | check_diagnostics( | ||
1132 | r#" | ||
1133 | fn main() { | ||
1134 | match true { | ||
1135 | true if false => {} | ||
1136 | true => {} | ||
1137 | false => {} | ||
1138 | } | ||
1139 | match true { | ||
1140 | //^^^^ Missing match arm | ||
1141 | true if false => {} | ||
1142 | false => {} | ||
1143 | } | ||
1144 | "#, | ||
1145 | ); | ||
1146 | } | ||
1147 | |||
1129 | mod false_negatives { | 1148 | mod false_negatives { |
1130 | //! The implementation of match checking here is a work in progress. As we roll this out, we | 1149 | //! The implementation of match checking here is a work in progress. As we roll this out, we |
1131 | //! prefer false negatives to false positives (ideally there would be no false positives). This | 1150 | //! prefer false negatives to false positives (ideally there would be no false positives). This |
@@ -1153,5 +1172,37 @@ fn main() { | |||
1153 | "#, | 1172 | "#, |
1154 | ); | 1173 | ); |
1155 | } | 1174 | } |
1175 | |||
1176 | #[test] | ||
1177 | fn reference_patterns_at_top_level() { | ||
1178 | check_diagnostics( | ||
1179 | r#" | ||
1180 | fn main() { | ||
1181 | match &false { | ||
1182 | &true => {} | ||
1183 | // ^^^^^ Internal: match check bailed out | ||
1184 | } | ||
1185 | } | ||
1186 | "#, | ||
1187 | ); | ||
1188 | } | ||
1189 | |||
1190 | #[test] | ||
1191 | fn reference_patterns_in_fields() { | ||
1192 | check_diagnostics( | ||
1193 | r#" | ||
1194 | fn main() { | ||
1195 | match (&false,) { | ||
1196 | (true,) => {} | ||
1197 | // ^^^^^^^ Internal: match check bailed out | ||
1198 | } | ||
1199 | match (&false,) { | ||
1200 | (&true,) => {} | ||
1201 | // ^^^^^^^^ Internal: match check bailed out | ||
1202 | } | ||
1203 | } | ||
1204 | "#, | ||
1205 | ); | ||
1206 | } | ||
1156 | } | 1207 | } |
1157 | } | 1208 | } |