about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-03-03 11:13:06 +0100
committerLukas Wirth <lukastw97@gmail.com>2023-03-03 11:13:06 +0100
commit522823f610391932e2f4162a8c929af2dacaefc4 (patch)
tree98488def8ae5a5985916bd3960837cf548b74c07
parent44e2c6ea9207264a86d05344b67999d77687edb6 (diff)
downloadrust-522823f610391932e2f4162a8c929af2dacaefc4.tar.gz
rust-522823f610391932e2f4162a8c929af2dacaefc4.zip
Fix text fixtures of missing_match_arms diagnostics
-rw-r--r--crates/hir-ty/src/infer/expr.rs2
-rw-r--r--crates/hir-ty/src/infer/pat.rs3
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_match_arms.rs9
3 files changed, 11 insertions, 3 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index a186ae836d0..6f20f0dc893 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -398,7 +398,7 @@ impl<'a> InferenceContext<'a> {
                 for arm in arms.iter() {
                     self.diverges = Diverges::Maybe;
                     let input_ty = self.resolve_ty_shallow(&input_ty);
-                    let _pat_ty = self.infer_top_pat(arm.pat, &input_ty);
+                    self.infer_top_pat(arm.pat, &input_ty);
                     if let Some(guard_expr) = arm.guard {
                         self.infer_expr(
                             guard_expr,
diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs
index 4c97eabd9ce..3d03c2a527c 100644
--- a/crates/hir-ty/src/infer/pat.rs
+++ b/crates/hir-ty/src/infer/pat.rs
@@ -293,7 +293,8 @@ impl<'a> InferenceContext<'a> {
         };
         // use a new type variable if we got error type here
         let ty = self.insert_type_vars_shallow(ty);
-        if !self.unify(&ty, &expected) {
+        // FIXME: This never check is odd, but required with out we do inference right now
+        if !expected.is_never() && !self.unify(&ty, &expected) {
             self.result
                 .type_mismatches
                 .insert(pat.into(), TypeMismatch { expected, actual: ty.clone() });
diff --git a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
index c24430ce604..6594eed26d1 100644
--- a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
@@ -273,15 +273,20 @@ enum Either2 { C, D }
 fn main() {
     match Either::A {
         Either2::C => (),
+     // ^^^^^^^^^^  error: expected Either, found Either2
         Either2::D => (),
+     // ^^^^^^^^^^  error: expected Either, found Either2
     }
     match (true, false) {
         (true, false, true) => (),
+     // ^^^^^^^^^^^^^^^^^^^  error: expected (bool, bool), found (bool, bool, bool)
         (true) => (),
       // ^^^^  error: expected (bool, bool), found bool
     }
     match (true, false) { (true,) => {} }
+                       // ^^^^^^^  error: expected (bool, bool), found (bool,)
     match (0) { () => () }
+             // ^^  error: expected i32, found ()
     match Unresolved::Bar { Unresolved::Baz => () }
 }
         "#,
@@ -295,7 +300,9 @@ fn main() {
             r#"
 fn main() {
     match false { true | () => {} }
+                      // ^^  error: expected bool, found ()
     match (false,) { (true | (),) => {} }
+                          // ^^  error: expected bool, found ()
 }
 "#,
         );
@@ -1038,12 +1045,12 @@ fn main() {
         #[test]
         fn reference_patterns_in_fields() {
             cov_mark::check_count!(validate_match_bailed_out, 2);
-
             check_diagnostics(
                 r#"
 fn main() {
     match (&false,) {
         (true,) => {}
+     // ^^^^^^^  error: expected (&bool,), found (bool,)
     }
     match (&false,) {
         (&true,) => {}