@@ -367,6 +367,11 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
367
367
fn head < ' a > ( & ' a self ) -> & ' p Pat < ' tcx > {
368
368
self . 0 [ 0 ]
369
369
}
370
+
371
+ fn head_ctors ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> SmallVec < [ Constructor < ' tcx > ; 1 ] > {
372
+ pat_constructors ( cx. tcx , cx. param_env , self . head ( ) )
373
+ }
374
+
370
375
fn iter ( & self ) -> impl Iterator < Item = & Pat < ' tcx > > {
371
376
self . 0 . iter ( ) . map ( |p| * p)
372
377
}
@@ -427,6 +432,10 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
427
432
self . 0 . iter ( ) . map ( |r| r. head ( ) )
428
433
}
429
434
435
+ fn head_ctors ( & self , cx : & MatchCheckCtxt < ' _ , ' tcx > ) -> Vec < Constructor < ' tcx > > {
436
+ self . 0 . iter ( ) . flat_map ( |r| r. head_ctors ( cx) ) . filter ( |ctor| !ctor. is_wildcard ( ) ) . collect ( )
437
+ }
438
+
430
439
/// This computes `S(constructor, self)`. See top of the file for explanations.
431
440
fn specialize < ' a , ' q > (
432
441
& self ,
@@ -1747,7 +1756,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1747
1756
1748
1757
debug ! ( "is_useful_expand_first_col: ty={:#?}, expanding {:#?}" , ty, v. head( ) ) ;
1749
1758
1750
- let v_constructors = pat_constructors ( cx . tcx , cx . param_env , v . head ( ) ) ;
1759
+ let v_constructors = v . head_ctors ( cx ) ;
1751
1760
1752
1761
if cx. is_non_exhaustive_variant ( v. head ( ) )
1753
1762
&& !cx. is_local ( ty)
@@ -1758,11 +1767,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1758
1767
return Useful ;
1759
1768
}
1760
1769
1761
- let matrix_head_ctors: Vec < Constructor < ' _ > > = matrix
1762
- . heads ( )
1763
- . flat_map ( |p| pat_constructors ( cx. tcx , cx. param_env , p) )
1764
- . filter ( |ctor| !ctor. is_wildcard ( ) )
1765
- . collect ( ) ;
1770
+ let matrix_head_ctors = matrix. head_ctors ( cx) ;
1766
1771
debug ! ( "matrix_head_ctors = {:#?}" , matrix_head_ctors) ;
1767
1772
1768
1773
v_constructors
0 commit comments