From 977ba46bb113c9e9ec159f01a72f51a0a7b92c1b Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Wed, 12 May 2021 12:50:22 +0500 Subject: [PATCH] Test match guards, reference patterns --- crates/hir_ty/src/diagnostics/match_check.rs | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 061ef754db2..5fb98ff35c6 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() { ); } + #[test] + fn match_guard() { + check_diagnostics( + r#" +fn main() { + match true { + true if false => {} + true => {} + false => {} + } + match true { + //^^^^ Missing match arm + true if false => {} + false => {} +} +"#, + ); + } + mod false_negatives { //! The implementation of match checking here is a work in progress. As we roll this out, we //! prefer false negatives to false positives (ideally there would be no false positives). This @@ -1153,5 +1172,37 @@ fn main() { "#, ); } + + #[test] + fn reference_patterns_at_top_level() { + check_diagnostics( + r#" +fn main() { + match &false { + &true => {} + // ^^^^^ Internal: match check bailed out + } +} + "#, + ); + } + + #[test] + fn reference_patterns_in_fields() { + check_diagnostics( + r#" +fn main() { + match (&false,) { + (true,) => {} + // ^^^^^^^ Internal: match check bailed out + } + match (&false,) { + (&true,) => {} + // ^^^^^^^^ Internal: match check bailed out + } +} + "#, + ); + } } }