From e711abc29032ddd395b60fccc47063e49785168f Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Thu, 6 May 2021 17:18:51 +0500 Subject: Lower Pat::Path --- crates/hir_ty/src/diagnostics/pattern.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/hir_ty') 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> { let kind = match self.body[pat] { hir_def::expr::Pat::Wild => PatKind::Wild, + hir_def::expr::Pat::Path(ref path) => { + return self.lower_path(pat, path); + } + hir_def::expr::Pat::Tuple { ref args, ellipsis } => { let arity = match *ty.kind(&Interner) { TyKind::Tuple(arity, _) => arity, @@ -193,6 +197,20 @@ impl<'a> PatCtxt<'a> { // TODO: do we need PatKind::AscribeUserType ? kind } + + fn lower_path(&mut self, pat: hir_def::expr::PatId, path: &hir_def::path::Path) -> Pat { + let ty = &self.infer[pat]; + + let pat_from_kind = |kind| Pat { ty: ty.clone(), kind: Box::new(kind) }; + + match self.infer.variant_resolution_for_pat(pat) { + Some(_) => pat_from_kind(self.lower_variant_or_leaf(pat, ty, Vec::new())), + None => { + self.errors.push(PatternError::Unimplemented); + pat_from_kind(PatKind::Wild) + } + } + } } #[cfg(test)] -- cgit v1.2.3