@@ -362,7 +362,12 @@ impl PatStack {
362
362
cx : & MatchCheckCtx ,
363
363
constructor : & Constructor ,
364
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
371
( Pat :: Tuple { args : ref pat_ids, ellipsis } , Constructor :: Tuple { arity : _ } ) => {
367
372
if ellipsis. is_some ( ) {
368
373
// If there are ellipsis here, we should add the correct number of
@@ -531,7 +536,7 @@ impl Matrix {
531
536
}
532
537
533
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
542
/// Computes `D(self)` for each contained PatStack.
@@ -1992,6 +1997,25 @@ mod tests {
1992
1997
1993
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
2021
#[ cfg( test) ]
0 commit comments