File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -1386,6 +1386,42 @@ mod tests {
13861386 // we don't create a diagnostic).
13871387 check_no_diagnostic ( content) ;
13881388 }
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+ }
13891425}
13901426
13911427#[ cfg( test) ]
@@ -1455,4 +1491,45 @@ mod false_negatives {
14551491 // We do not currently handle patterns with internal `or`s.
14561492 check_no_diagnostic ( content) ;
14571493 }
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+ }
14581535}
You can’t perform that action at this time.
0 commit comments