diff options
author | Dawer <[email protected]> | 2021-05-06 13:18:51 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:03:47 +0100 |
commit | e711abc29032ddd395b60fccc47063e49785168f (patch) | |
tree | 13a21ef0173733283f263193d6bbbf116da2ca9e /crates/hir_ty/src/diagnostics | |
parent | e50ce67631bc8f8e28042112a924b73c6081dc71 (diff) |
Lower Pat::Path
Diffstat (limited to 'crates/hir_ty/src/diagnostics')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern.rs b/crates/hir_ty/src/diagnostics/pattern.rs index 6646826b3..5c9419d2c 100644 --- a/crates/hir_ty/src/diagnostics/pattern.rs +++ b/crates/hir_ty/src/diagnostics/pattern.rs | |||
@@ -99,6 +99,10 @@ impl<'a> PatCtxt<'a> { | |||
99 | let kind = match self.body[pat] { | 99 | let kind = match self.body[pat] { |
100 | hir_def::expr::Pat::Wild => PatKind::Wild, | 100 | hir_def::expr::Pat::Wild => PatKind::Wild, |
101 | 101 | ||
102 | hir_def::expr::Pat::Path(ref path) => { | ||
103 | return self.lower_path(pat, path); | ||
104 | } | ||
105 | |||
102 | hir_def::expr::Pat::Tuple { ref args, ellipsis } => { | 106 | hir_def::expr::Pat::Tuple { ref args, ellipsis } => { |
103 | let arity = match *ty.kind(&Interner) { | 107 | let arity = match *ty.kind(&Interner) { |
104 | TyKind::Tuple(arity, _) => arity, | 108 | TyKind::Tuple(arity, _) => arity, |
@@ -193,6 +197,20 @@ impl<'a> PatCtxt<'a> { | |||
193 | // TODO: do we need PatKind::AscribeUserType ? | 197 | // TODO: do we need PatKind::AscribeUserType ? |
194 | kind | 198 | kind |
195 | } | 199 | } |
200 | |||
201 | fn lower_path(&mut self, pat: hir_def::expr::PatId, path: &hir_def::path::Path) -> Pat { | ||
202 | let ty = &self.infer[pat]; | ||
203 | |||
204 | let pat_from_kind = |kind| Pat { ty: ty.clone(), kind: Box::new(kind) }; | ||
205 | |||
206 | match self.infer.variant_resolution_for_pat(pat) { | ||
207 | Some(_) => pat_from_kind(self.lower_variant_or_leaf(pat, ty, Vec::new())), | ||
208 | None => { | ||
209 | self.errors.push(PatternError::Unimplemented); | ||
210 | pat_from_kind(PatKind::Wild) | ||
211 | } | ||
212 | } | ||
213 | } | ||
196 | } | 214 | } |
197 | 215 | ||
198 | #[cfg(test)] | 216 | #[cfg(test)] |