@@ -26,23 +26,23 @@ pub struct DeconstructedPat<'p, Cx: MatchCx> {
2626 ctor : Constructor < Cx > ,
2727 fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
2828 ty : Cx :: Ty ,
29- span : Cx :: Span ,
29+ data : Cx :: PatData ,
3030 /// Whether removing this arm would change the behavior of the match expression.
3131 useful : Cell < bool > ,
3232}
3333
3434impl < ' p , Cx : MatchCx > DeconstructedPat < ' p , Cx > {
35- pub fn wildcard ( ty : Cx :: Ty , span : Cx :: Span ) -> Self {
36- Self :: new ( Wildcard , & [ ] , ty, span )
35+ pub fn wildcard ( ty : Cx :: Ty , data : Cx :: PatData ) -> Self {
36+ Self :: new ( Wildcard , & [ ] , ty, data )
3737 }
3838
3939 pub fn new (
4040 ctor : Constructor < Cx > ,
4141 fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
4242 ty : Cx :: Ty ,
43- span : Cx :: Span ,
43+ data : Cx :: PatData ,
4444 ) -> Self {
45- DeconstructedPat { ctor, fields, ty, span , useful : Cell :: new ( false ) }
45+ DeconstructedPat { ctor, fields, ty, data , useful : Cell :: new ( false ) }
4646 }
4747
4848 pub ( crate ) fn is_or_pat ( & self ) -> bool {
@@ -63,8 +63,8 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
6363 pub fn ty ( & self ) -> Cx :: Ty {
6464 self . ty
6565 }
66- pub fn span ( & self ) -> & Cx :: Span {
67- & self . span
66+ pub fn data ( & self ) -> & Cx :: PatData {
67+ & self . data
6868 }
6969
7070 pub fn iter_fields < ' a > (
@@ -83,7 +83,7 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
8383 let wildcard_sub_tys = || {
8484 let tys = pcx. cx . ctor_sub_tys ( other_ctor, pcx. ty ) ;
8585 tys. iter ( )
86- . map ( |ty| DeconstructedPat :: wildcard ( * ty, Cx :: Span :: default ( ) ) )
86+ . map ( |ty| DeconstructedPat :: wildcard ( * ty, Cx :: PatData :: default ( ) ) )
8787 . map ( |pat| pcx. wildcard_arena . alloc ( pat) as & _ )
8888 . collect ( )
8989 } ;
@@ -113,8 +113,8 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
113113 }
114114 }
115115
116- /// We keep track for each pattern if it was ever useful during the analysis. This is used
117- /// with `redundant_spans ` to report redundant subpatterns arising from or patterns.
116+ /// We keep track for each pattern if it was ever useful during the analysis. This is used with
117+ /// `redundant_subpatterns ` to report redundant subpatterns arising from or patterns.
118118 pub ( crate ) fn set_useful ( & self ) {
119119 self . useful . set ( true )
120120 }
@@ -132,19 +132,19 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
132132 }
133133 }
134134
135- /// Report the spans of subpatterns that were not useful, if any.
136- pub ( crate ) fn redundant_spans ( & self ) -> Vec < Cx :: Span > {
137- let mut spans = Vec :: new ( ) ;
138- self . collect_redundant_spans ( & mut spans ) ;
139- spans
135+ /// Report the subpatterns that were not useful, if any.
136+ pub ( crate ) fn redundant_subpatterns ( & self ) -> Vec < & Self > {
137+ let mut subpats = Vec :: new ( ) ;
138+ self . collect_redundant_subpatterns ( & mut subpats ) ;
139+ subpats
140140 }
141- fn collect_redundant_spans ( & self , spans : & mut Vec < Cx :: Span > ) {
141+ fn collect_redundant_subpatterns < ' a > ( & ' a self , subpats : & mut Vec < & ' a Self > ) {
142142 // We don't look at subpatterns if we already reported the whole pattern as redundant.
143143 if !self . is_useful ( ) {
144- spans . push ( self . span . clone ( ) ) ;
144+ subpats . push ( self ) ;
145145 } else {
146146 for p in self . iter_fields ( ) {
147- p. collect_redundant_spans ( spans ) ;
147+ p. collect_redundant_subpatterns ( subpats ) ;
148148 }
149149 }
150150 }
0 commit comments