@@ -416,7 +416,7 @@ impl<'tcx> Pat<'tcx> {
416416
417417/// A row of a matrix. Rows of len 1 are very common, which is why `SmallVec[_; 2]`
418418/// works well.
419- #[ derive( Debug , Clone ) ]
419+ #[ derive( Debug , Clone , PartialEq ) ]
420420crate struct PatStack < ' p , ' tcx > ( SmallVec < [ & ' p Pat < ' tcx > ; 2 ] > ) ;
421421
422422impl < ' p , ' tcx > PatStack < ' p , ' tcx > {
@@ -506,7 +506,7 @@ impl<'p, 'tcx> FromIterator<&'p Pat<'tcx>> for PatStack<'p, 'tcx> {
506506
507507/// Depending on the match patterns, the specialization process might be able to use a fast path.
508508/// Tracks whether we can use the fast path and the lookup table needed in those cases.
509- #[ derive( Clone , Debug ) ]
509+ #[ derive( Clone , Debug , PartialEq ) ]
510510enum SpecializationCache {
511511 /// Patterns consist of only enum variants.
512512 /// Variant patterns does not intersect with each other (in contrast to range patterns),
@@ -523,7 +523,7 @@ enum SpecializationCache {
523523}
524524
525525/// A 2D matrix.
526- #[ derive( Clone ) ]
526+ #[ derive( Clone , PartialEq ) ]
527527crate struct Matrix < ' p , ' tcx > {
528528 patterns : Vec < PatStack < ' p , ' tcx > > ,
529529 cache : SpecializationCache ,
@@ -622,7 +622,19 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
622622 fn specialize_wildcard ( & self ) -> Self {
623623 match & self . cache {
624624 SpecializationCache :: Variants { wilds, .. } => {
625- wilds. iter ( ) . filter_map ( |& i| self . patterns [ i] . specialize_wildcard ( ) ) . collect ( )
625+ let result =
626+ wilds. iter ( ) . filter_map ( |& i| self . patterns [ i] . specialize_wildcard ( ) ) . collect ( ) ;
627+ // When debug assertions are enabled, check the results against the "slow path"
628+ // result.
629+ debug_assert_eq ! (
630+ result,
631+ Self {
632+ patterns: self . patterns. clone( ) ,
633+ cache: SpecializationCache :: Incompatible
634+ }
635+ . specialize_wildcard( )
636+ ) ;
637+ result
626638 }
627639 SpecializationCache :: Incompatible => {
628640 self . patterns . iter ( ) . filter_map ( |r| r. specialize_wildcard ( ) ) . collect ( )
@@ -639,7 +651,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
639651 ) -> Matrix < ' p , ' tcx > {
640652 match & self . cache {
641653 SpecializationCache :: Variants { lookup, wilds } => {
642- if let Constructor :: Variant ( id) = constructor {
654+ let result : Self = if let Constructor :: Variant ( id) = constructor {
643655 lookup
644656 . get ( id)
645657 // Default to `wilds` for absent keys. See `update_cache` for an explanation.
@@ -655,7 +667,22 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
655667 . collect ( )
656668 } else {
657669 unreachable ! ( )
658- }
670+ } ;
671+ // When debug assertions are enabled, check the results against the "slow path"
672+ // result.
673+ debug_assert_eq ! (
674+ result,
675+ Matrix {
676+ patterns: self . patterns. clone( ) ,
677+ cache: SpecializationCache :: Incompatible
678+ }
679+ . specialize_constructor(
680+ cx,
681+ constructor,
682+ ctor_wild_subpatterns
683+ )
684+ ) ;
685+ result
659686 }
660687 SpecializationCache :: Incompatible => self
661688 . patterns
0 commit comments