diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-19 18:46:38 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-19 18:46:38 +0100 |
commit | c7196620abd5e9bab4fbd53388da361f0f6987a1 (patch) | |
tree | 3511921f52d08ea88da3d650cfb835dffef2c8de /crates/hir_ty/src/infer | |
parent | 1cf0794f5eac5de7a3829fe93a1b99f4d22fd2f0 (diff) | |
parent | e2b1c69f7488b942360bb3c398a1c831510d1afc (diff) |
Merge #8875
8875: fix: false positive "Missing match arm" when an or-pattern has mismatched types r=flodiebold a=iDawer
![Screenshot_20210519_114510](https://user-images.githubusercontent.com/7803845/118768935-19e12c00-b86f-11eb-90c4-1eed3f2bf57f.jpg)
`InferenceResult` now records pattern type mismatches.
Co-authored-by: Dawer <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index b6b5a1b75..7278faeec 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -42,7 +42,7 @@ impl<'a> InferenceContext<'a> { | |||
42 | let could_unify = self.unify(&ty, &expected.ty); | 42 | let could_unify = self.unify(&ty, &expected.ty); |
43 | if !could_unify { | 43 | if !could_unify { |
44 | self.result.type_mismatches.insert( | 44 | self.result.type_mismatches.insert( |
45 | tgt_expr, | 45 | tgt_expr.into(), |
46 | TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, | 46 | TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, |
47 | ); | 47 | ); |
48 | } | 48 | } |
@@ -54,9 +54,10 @@ impl<'a> InferenceContext<'a> { | |||
54 | pub(super) fn infer_expr_coerce(&mut self, expr: ExprId, expected: &Expectation) -> Ty { | 54 | pub(super) fn infer_expr_coerce(&mut self, expr: ExprId, expected: &Expectation) -> Ty { |
55 | let ty = self.infer_expr_inner(expr, &expected); | 55 | let ty = self.infer_expr_inner(expr, &expected); |
56 | let ty = if !self.coerce(&ty, &expected.coercion_target()) { | 56 | let ty = if !self.coerce(&ty, &expected.coercion_target()) { |
57 | self.result | 57 | self.result.type_mismatches.insert( |
58 | .type_mismatches | 58 | expr.into(), |
59 | .insert(expr, TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }); | 59 | TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, |
60 | ); | ||
60 | // Return actual type when type mismatch. | 61 | // Return actual type when type mismatch. |
61 | // This is needed for diagnostic when return type mismatch. | 62 | // This is needed for diagnostic when return type mismatch. |
62 | ty | 63 | ty |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 60b94a642..b15f4977d 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -10,7 +10,7 @@ use hir_def::{ | |||
10 | }; | 10 | }; |
11 | use hir_expand::name::Name; | 11 | use hir_expand::name::Name; |
12 | 12 | ||
13 | use super::{BindingMode, Expectation, InferenceContext}; | 13 | use super::{BindingMode, Expectation, InferenceContext, TypeMismatch}; |
14 | use crate::{ | 14 | use crate::{ |
15 | lower::lower_to_chalk_mutability, static_lifetime, Interner, Substitution, Ty, TyBuilder, | 15 | lower::lower_to_chalk_mutability, static_lifetime, Interner, Substitution, Ty, TyBuilder, |
16 | TyExt, TyKind, | 16 | TyExt, TyKind, |
@@ -266,7 +266,10 @@ impl<'a> InferenceContext<'a> { | |||
266 | // use a new type variable if we got error type here | 266 | // use a new type variable if we got error type here |
267 | let ty = self.insert_type_vars_shallow(ty); | 267 | let ty = self.insert_type_vars_shallow(ty); |
268 | if !self.unify(&ty, expected) { | 268 | if !self.unify(&ty, expected) { |
269 | // FIXME record mismatch, we need to change the type of self.type_mismatches for that | 269 | self.result.type_mismatches.insert( |
270 | pat.into(), | ||
271 | TypeMismatch { expected: expected.clone(), actual: ty.clone() }, | ||
272 | ); | ||
270 | } | 273 | } |
271 | let ty = self.resolve_ty_as_possible(ty); | 274 | let ty = self.resolve_ty_as_possible(ty); |
272 | self.write_pat_ty(pat, ty.clone()); | 275 | self.write_pat_ty(pat, ty.clone()); |