diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-07 13:53:47 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-07 13:53:47 +0100 |
commit | 97b963b44b9da1fca4229da4c8744fa88c25780b (patch) | |
tree | f25e0db350072cf8d084ce81adcaeeeaac3f4c42 /crates/ra_hir_ty/src/infer/pat.rs | |
parent | b7e5d94bda362ffc21174a79aa0be113c3288e1e (diff) | |
parent | 9fc1f51b7ade2cda7d410450ab1347311eb074af (diff) |
Merge #3706
3706: missing match arms diagnostic r=flodiebold a=JoshMcguigan
Following up on https://github.com/rust-analyzer/rust-analyzer/pull/3689#issuecomment-602718222, this PR creates a missing match arms diagnostic.
At the moment this is a very early draft, but I wanted to open it just to get some initial feedback.
Initial questions:
* Have I roughly created the correct boilerplate?
* Inside the new `validate_match` function:
* Am I correct in thinking I want to do validation by comparing the match arms against `match_expr`? And when analyzing `match_expr` I should be looking at it as a `hir_def::expr::Expr`?
* I mostly copied the chained if-let statements from the struct validation. Shouldn't there be a non-failable way to get an AstPtr from the hir data structures?
Thanks for all the guidance.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/infer/pat.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer/pat.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 86acd27f8..69bbb4307 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs | |||
@@ -21,9 +21,13 @@ impl<'a> InferenceContext<'a> { | |||
21 | subpats: &[PatId], | 21 | subpats: &[PatId], |
22 | expected: &Ty, | 22 | expected: &Ty, |
23 | default_bm: BindingMode, | 23 | default_bm: BindingMode, |
24 | id: PatId, | ||
24 | ) -> Ty { | 25 | ) -> Ty { |
25 | let (ty, def) = self.resolve_variant(path); | 26 | let (ty, def) = self.resolve_variant(path); |
26 | let var_data = def.map(|it| variant_data(self.db.upcast(), it)); | 27 | let var_data = def.map(|it| variant_data(self.db.upcast(), it)); |
28 | if let Some(variant) = def { | ||
29 | self.write_variant_resolution(id.into(), variant); | ||
30 | } | ||
27 | self.unify(&ty, expected); | 31 | self.unify(&ty, expected); |
28 | 32 | ||
29 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 33 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
@@ -152,7 +156,7 @@ impl<'a> InferenceContext<'a> { | |||
152 | Ty::apply_one(TypeCtor::Ref(*mutability), subty) | 156 | Ty::apply_one(TypeCtor::Ref(*mutability), subty) |
153 | } | 157 | } |
154 | Pat::TupleStruct { path: p, args: subpats } => { | 158 | Pat::TupleStruct { path: p, args: subpats } => { |
155 | self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) | 159 | self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm, pat) |
156 | } | 160 | } |
157 | Pat::Record { path: p, args: fields } => { | 161 | Pat::Record { path: p, args: fields } => { |
158 | self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) | 162 | self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) |