aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/_match.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs
index 342a78b45..4be08e9a3 100644
--- a/crates/ra_hir_ty/src/_match.rs
+++ b/crates/ra_hir_ty/src/_match.rs
@@ -1386,6 +1386,42 @@ mod tests {
1386 // we don't create a diagnostic). 1386 // we don't create a diagnostic).
1387 check_no_diagnostic(content); 1387 check_no_diagnostic(content);
1388 } 1388 }
1389
1390 #[test]
1391 fn expr_diverges() {
1392 let content = r"
1393 enum Either {
1394 A,
1395 B,
1396 }
1397 fn test_fn() {
1398 match loop {} {
1399 Either::A => (),
1400 Either::B => (),
1401 }
1402 }
1403 ";
1404
1405 check_no_diagnostic(content);
1406 }
1407
1408 #[test]
1409 fn expr_loop_with_break() {
1410 let content = r"
1411 enum Either {
1412 A,
1413 B,
1414 }
1415 fn test_fn() {
1416 match loop { break Foo::A } {
1417 Either::A => (),
1418 Either::B => (),
1419 }
1420 }
1421 ";
1422
1423 check_no_diagnostic(content);
1424 }
1389} 1425}
1390 1426
1391#[cfg(test)] 1427#[cfg(test)]
@@ -1455,4 +1491,45 @@ mod false_negatives {
1455 // We do not currently handle patterns with internal `or`s. 1491 // We do not currently handle patterns with internal `or`s.
1456 check_no_diagnostic(content); 1492 check_no_diagnostic(content);
1457 } 1493 }
1494
1495 #[test]
1496 fn expr_diverges_missing_arm() {
1497 let content = r"
1498 enum Either {
1499 A,
1500 B,
1501 }
1502 fn test_fn() {
1503 match loop {} {
1504 Either::A => (),
1505 }
1506 }
1507 ";
1508
1509 // This is a false negative.
1510 // Even though the match expression diverges, rustc fails
1511 // to compile here since `Either::B` is missing.
1512 check_no_diagnostic(content);
1513 }
1514
1515 #[test]
1516 fn expr_loop_missing_arm() {
1517 let content = r"
1518 enum Either {
1519 A,
1520 B,
1521 }
1522 fn test_fn() {
1523 match loop { break Foo::A } {
1524 Either::A => (),
1525 }
1526 }
1527 ";
1528
1529 // This is a false negative.
1530 // We currently infer the type of `loop { break Foo::A }` to `!`, which
1531 // causes us to skip the diagnostic since `Either::A` doesn't type check
1532 // with `!`.
1533 check_no_diagnostic(content);
1534 }
1458} 1535}