From 26e5bb0a4efbe894d33cde3c1bc3f712fcf33cde Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 11 Apr 2020 07:07:47 -0700 Subject: missing match arms add tests for match expression diverging --- crates/ra_hir_ty/src/_match.rs | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'crates/ra_hir_ty/src') 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 { // we don't create a diagnostic). check_no_diagnostic(content); } + + #[test] + fn expr_diverges() { + let content = r" + enum Either { + A, + B, + } + fn test_fn() { + match loop {} { + Either::A => (), + Either::B => (), + } + } + "; + + check_no_diagnostic(content); + } + + #[test] + fn expr_loop_with_break() { + let content = r" + enum Either { + A, + B, + } + fn test_fn() { + match loop { break Foo::A } { + Either::A => (), + Either::B => (), + } + } + "; + + check_no_diagnostic(content); + } } #[cfg(test)] @@ -1455,4 +1491,45 @@ mod false_negatives { // We do not currently handle patterns with internal `or`s. check_no_diagnostic(content); } + + #[test] + fn expr_diverges_missing_arm() { + let content = r" + enum Either { + A, + B, + } + fn test_fn() { + match loop {} { + Either::A => (), + } + } + "; + + // This is a false negative. + // Even though the match expression diverges, rustc fails + // to compile here since `Either::B` is missing. + check_no_diagnostic(content); + } + + #[test] + fn expr_loop_missing_arm() { + let content = r" + enum Either { + A, + B, + } + fn test_fn() { + match loop { break Foo::A } { + Either::A => (), + } + } + "; + + // This is a false negative. + // We currently infer the type of `loop { break Foo::A }` to `!`, which + // causes us to skip the diagnostic since `Either::A` doesn't type check + // with `!`. + check_no_diagnostic(content); + } } -- cgit v1.2.3