Unnamed repository; edit this file 'description' to name the repository.
Fix text fixtures of missing_match_arms diagnostics
Lukas Wirth 2023-03-03
parent 44e2c6e · commit 522823f
-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 a186ae836d..6f20f0dc89 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 4c97eabd9c..3d03c2a527 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 c24430ce60..6594eed26d 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,) => {}