Fix text fixtures of missing_match_arms diagnostics

This commit is contained in:
Lukas Wirth 2023-03-03 11:13:06 +01:00
parent 44e2c6ea92
commit 522823f610
3 changed files with 11 additions and 3 deletions

View File

@ -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,

View File

@ -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() });

View File

@ -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,) => {}