aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs5
-rw-r--r--crates/ra_hir/src/ty/tests.rs7
2 files changed, 11 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index dc7101075..b310bf6bd 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1096,8 +1096,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1096 } 1096 }
1097 let arm_ty = self.infer_expr(arm.expr, &expected); 1097 let arm_ty = self.infer_expr(arm.expr, &expected);
1098 if all_arms_never && Self::is_never(&arm_ty) { 1098 if all_arms_never && Self::is_never(&arm_ty) {
1099 tested_by!(match_first_arm_never);
1099 resulting_match_ty = Some(arm_ty); 1100 resulting_match_ty = Some(arm_ty);
1100 } else { 1101 } else {
1102 tested_by!(match_second_arm_never);
1101 all_arms_never = false; 1103 all_arms_never = false;
1102 resulting_match_ty = None; 1104 resulting_match_ty = None;
1103 } 1105 }
@@ -1106,10 +1108,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1106 if let (Ty::Infer(expected_tv), Some(match_ty)) = 1108 if let (Ty::Infer(expected_tv), Some(match_ty)) =
1107 (&expected.ty, &resulting_match_ty) 1109 (&expected.ty, &resulting_match_ty)
1108 { 1110 {
1111 tested_by!(match_all_arms_never);
1109 self.var_unification_table 1112 self.var_unification_table
1110 .union_value(expected_tv.to_inner(), TypeVarValue::Known(match_ty.clone())); 1113 .union_value(expected_tv.to_inner(), TypeVarValue::Known(match_ty.clone()));
1111 match_ty.clone() 1114 match_ty.clone()
1112 } else { 1115 } else {
1116 tested_by!(match_no_never_arms);
1117 tested_by!(match_complex_arm_ty);
1113 expected.ty 1118 expected.ty
1114 } 1119 }
1115 } 1120 }
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 6bf56959d..7ec834836 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -3595,12 +3595,13 @@ fn no_such_field_diagnostics() {
3595 ); 3595 );
3596} 3596}
3597 3597
3598#[cfg(test)]
3599mod match_with_never_tests { 3598mod match_with_never_tests {
3600 use super::type_at; 3599 use super::type_at;
3600 use test_utils::covers;
3601 3601
3602 #[test] 3602 #[test]
3603 fn match_complex_arm_ty() { 3603 fn match_complex_arm_ty() {
3604 covers!(match_complex_arm_ty);
3604 let t = type_at( 3605 let t = type_at(
3605 r#" 3606 r#"
3606//- /main.rs 3607//- /main.rs
@@ -3624,6 +3625,7 @@ fn test(a: i32) {
3624 3625
3625 #[test] 3626 #[test]
3626 fn match_first_arm_never() { 3627 fn match_first_arm_never() {
3628 covers!(match_first_arm_never);
3627 let t = type_at( 3629 let t = type_at(
3628 r#" 3630 r#"
3629//- /main.rs 3631//- /main.rs
@@ -3644,6 +3646,7 @@ fn test(a: i32) {
3644 3646
3645 #[test] 3647 #[test]
3646 fn match_second_arm_never() { 3648 fn match_second_arm_never() {
3649 covers!(match_second_arm_never);
3647 let t = type_at( 3650 let t = type_at(
3648 r#" 3651 r#"
3649//- /main.rs 3652//- /main.rs
@@ -3664,6 +3667,7 @@ fn test(a: i32) {
3664 3667
3665 #[test] 3668 #[test]
3666 fn match_all_arms_never() { 3669 fn match_all_arms_never() {
3670 covers!(match_all_arms_never);
3667 let t = type_at( 3671 let t = type_at(
3668 r#" 3672 r#"
3669//- /main.rs 3673//- /main.rs
@@ -3682,6 +3686,7 @@ fn test(a: i32) {
3682 3686
3683 #[test] 3687 #[test]
3684 fn match_no_never_arms() { 3688 fn match_no_never_arms() {
3689 covers!(match_no_never_arms);
3685 let t = type_at( 3690 let t = type_at(
3686 r#" 3691 r#"
3687//- /main.rs 3692//- /main.rs