aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-11 20:48:31 +0000
committerGitHub <[email protected]>2020-02-11 20:48:31 +0000
commit6f685df68164aaf261ebd30a7bb8c81be96c8c77 (patch)
treeb6181771c1b322d5a5acf6d6b1aa67c2bfaaedec
parent00e672a51b0caec9e2bb7004281ce2f57bdbefe5 (diff)
parent43df7c3d53198e8ae3509035eb5273d8a94f758b (diff)
Merge #3114
3114: Don't let unknown match arms fall back to ! r=kjeremy a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs6
-rw-r--r--crates/ra_hir_ty/src/tests/never_type.rs17
2 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 186857b8b..39d8bc0ca 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -165,7 +165,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
165 Expr::Match { expr, arms } => { 165 Expr::Match { expr, arms } => {
166 let input_ty = self.infer_expr(*expr, &Expectation::none()); 166 let input_ty = self.infer_expr(*expr, &Expectation::none());
167 167
168 let mut result_ty = self.table.new_maybe_never_type_var(); 168 let mut result_ty = if arms.len() == 0 {
169 Ty::simple(TypeCtor::Never)
170 } else {
171 self.table.new_type_var()
172 };
169 173
170 for arm in arms { 174 for arm in arms {
171 let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default()); 175 let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default());
diff --git a/crates/ra_hir_ty/src/tests/never_type.rs b/crates/ra_hir_ty/src/tests/never_type.rs
index c202f545a..a77209480 100644
--- a/crates/ra_hir_ty/src/tests/never_type.rs
+++ b/crates/ra_hir_ty/src/tests/never_type.rs
@@ -101,6 +101,7 @@ fn test() {
101 ); 101 );
102 assert_eq!(t, "Option<i32>"); 102 assert_eq!(t, "Option<i32>");
103} 103}
104
104#[test] 105#[test]
105fn never_type_can_be_reinferred3() { 106fn never_type_can_be_reinferred3() {
106 let t = type_at( 107 let t = type_at(
@@ -138,6 +139,22 @@ fn test(a: Void) {
138} 139}
139 140
140#[test] 141#[test]
142fn match_unknown_arm() {
143 let t = type_at(
144 r#"
145//- /main.rs
146fn test(a: Option) {
147 let t = match 0 {
148 _ => unknown,
149 };
150 t<|>;
151}
152"#,
153 );
154 assert_eq!(t, "{unknown}");
155}
156
157#[test]
141fn if_never() { 158fn if_never() {
142 let t = type_at( 159 let t = type_at(
143 r#" 160 r#"