From 408f914bf4d6719ae68582ae43e2de9d3cb362b0 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Fri, 17 Apr 2020 05:36:44 -0700 Subject: fix panic on ellipsis in pattern --- crates/ra_hir_def/src/body/lower.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 79abe55ce..0679ffa1e 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -650,6 +650,7 @@ impl ExprCollector<'_> { ast::Pat::SlicePat(p) => { let SlicePatComponents { prefix, slice, suffix } = p.components(); + // FIXME properly handle `DotDotPat` Pat::Slice { prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(), slice: slice.map(|p| self.collect_pat(p)), @@ -666,9 +667,15 @@ impl ExprCollector<'_> { Pat::Missing } } - ast::Pat::DotDotPat(_) => unreachable!( - "`DotDotPat` requires special handling and should not be mapped to a Pat." - ), + ast::Pat::DotDotPat(_) => { + // `DotDotPat` requires special handling and should not be mapped + // to a Pat. Here we are using `Pat::Missing` as a fallback for + // when `DotDotPat` is mapped to `Pat`, which can easily happen + // when the source code being analyzed has a malformed pattern + // which includes `..` in a place where it isn't valid. + + Pat::Missing + } // FIXME: implement ast::Pat::BoxPat(_) | ast::Pat::RangePat(_) | ast::Pat::MacroPat(_) => Pat::Missing, }; -- cgit v1.2.3