@@ -362,7 +362,12 @@ impl PatStack {
362362 cx : & MatchCheckCtx ,
363363 constructor : & Constructor ,
364364 ) -> 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) {
366371 ( Pat :: Tuple { args : ref pat_ids, ellipsis } , Constructor :: Tuple { arity : _ } ) => {
367372 if ellipsis. is_some ( ) {
368373 // If there are ellipsis here, we should add the correct number of
@@ -531,7 +536,7 @@ impl Matrix {
531536 }
532537
533538 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 ( )
535540 }
536541
537542 /// Computes `D(self)` for each contained PatStack.
@@ -1992,6 +1997,25 @@ mod tests {
19921997
19931998 check_no_diagnostic ( content) ;
19941999 }
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+ }
19952019}
19962020
19972021#[ cfg( test) ]
0 commit comments