@@ -367,6 +367,11 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
367367 fn head < ' a > ( & ' a self ) -> & ' p Pat < ' tcx > {
368368 self . 0 [ 0 ]
369369 }
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+
370375 fn iter ( & self ) -> impl Iterator < Item = & Pat < ' tcx > > {
371376 self . 0 . iter ( ) . map ( |p| * p)
372377 }
@@ -427,6 +432,10 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
427432 self . 0 . iter ( ) . map ( |r| r. head ( ) )
428433 }
429434
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+
430439 /// This computes `S(constructor, self)`. See top of the file for explanations.
431440 fn specialize < ' a , ' q > (
432441 & self ,
@@ -1747,7 +1756,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
17471756
17481757 debug ! ( "is_useful_expand_first_col: ty={:#?}, expanding {:#?}" , ty, v. head( ) ) ;
17491758
1750- let v_constructors = pat_constructors ( cx . tcx , cx . param_env , v . head ( ) ) ;
1759+ let v_constructors = v . head_ctors ( cx ) ;
17511760
17521761 if cx. is_non_exhaustive_variant ( v. head ( ) )
17531762 && !cx. is_local ( ty)
@@ -1758,11 +1767,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
17581767 return Useful ;
17591768 }
17601769
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) ;
17661771 debug ! ( "matrix_head_ctors = {:#?}" , matrix_head_ctors) ;
17671772
17681773 v_constructors
0 commit comments