aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/src/_match.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs
index fff257193..42004282c 100644
--- a/crates/ra_hir_ty/src/_match.rs
+++ b/crates/ra_hir_ty/src/_match.rs
@@ -362,7 +362,12 @@ impl PatStack {
362 cx: &MatchCheckCtx, 362 cx: &MatchCheckCtx,
363 constructor: &Constructor, 363 constructor: &Constructor,
364 ) -> MatchCheckResult<Option<PatStack>> { 364 ) -> MatchCheckResult<Option<PatStack>> {
365 let result = match (self.head().as_pat(cx), constructor) { 365 if self.is_empty() {
366 return Ok(None);
367 }
368
369 let head_pat = self.head().as_pat(cx);
370 let result = match (head_pat, constructor) {
366 (Pat::Tuple { args: ref pat_ids, ellipsis }, Constructor::Tuple { arity: _ }) => { 371 (Pat::Tuple { args: ref pat_ids, ellipsis }, Constructor::Tuple { arity: _ }) => {
367 if ellipsis.is_some() { 372 if ellipsis.is_some() {
368 // If there are ellipsis here, we should add the correct number of 373 // If there are ellipsis here, we should add the correct number of
@@ -531,7 +536,7 @@ impl Matrix {
531 } 536 }
532 537
533 fn heads(&self) -> Vec<PatIdOrWild> { 538 fn heads(&self) -> Vec<PatIdOrWild> {
534 self.0.iter().map(|p| p.head()).collect() 539 self.0.iter().flat_map(|p| p.get_head()).collect()
535 } 540 }
536 541
537 /// Computes `D(self)` for each contained PatStack. 542 /// Computes `D(self)` for each contained PatStack.
@@ -1992,6 +1997,25 @@ mod tests {
1992 1997
1993 check_no_diagnostic(content); 1998 check_no_diagnostic(content);
1994 } 1999 }
2000
2001 #[test]
2002 fn or_pattern_panic() {
2003 let content = r"
2004 pub enum Category {
2005 Infinity,
2006 Zero,
2007 }
2008
2009 fn panic(a: Category, b: Category) {
2010 match (a, b) {
2011 (Category::Zero | Category::Infinity, _) => {}
2012 (_, Category::Zero | Category::Infinity) => {}
2013 }
2014 }
2015 ";
2016
2017 check_no_diagnostic(content);
2018 }
1995} 2019}
1996 2020
1997#[cfg(test)] 2021#[cfg(test)]