@@ -26,23 +26,23 @@ pub struct DeconstructedPat<'p, Cx: MatchCx> {
26
26
ctor : Constructor < Cx > ,
27
27
fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
28
28
ty : Cx :: Ty ,
29
- span : Cx :: Span ,
29
+ data : Cx :: PatData ,
30
30
/// Whether removing this arm would change the behavior of the match expression.
31
31
useful : Cell < bool > ,
32
32
}
33
33
34
34
impl < ' 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 )
37
37
}
38
38
39
39
pub fn new (
40
40
ctor : Constructor < Cx > ,
41
41
fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
42
42
ty : Cx :: Ty ,
43
- span : Cx :: Span ,
43
+ data : Cx :: PatData ,
44
44
) -> Self {
45
- DeconstructedPat { ctor, fields, ty, span , useful : Cell :: new ( false ) }
45
+ DeconstructedPat { ctor, fields, ty, data , useful : Cell :: new ( false ) }
46
46
}
47
47
48
48
pub ( crate ) fn is_or_pat ( & self ) -> bool {
@@ -63,8 +63,8 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
63
63
pub fn ty ( & self ) -> Cx :: Ty {
64
64
self . ty
65
65
}
66
- pub fn span ( & self ) -> & Cx :: Span {
67
- & self . span
66
+ pub fn data ( & self ) -> & Cx :: PatData {
67
+ & self . data
68
68
}
69
69
70
70
pub fn iter_fields < ' a > (
@@ -83,7 +83,7 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
83
83
let wildcard_sub_tys = || {
84
84
let tys = pcx. cx . ctor_sub_tys ( other_ctor, pcx. ty ) ;
85
85
tys. iter ( )
86
- . map ( |ty| DeconstructedPat :: wildcard ( * ty, Cx :: Span :: default ( ) ) )
86
+ . map ( |ty| DeconstructedPat :: wildcard ( * ty, Cx :: PatData :: default ( ) ) )
87
87
. map ( |pat| pcx. wildcard_arena . alloc ( pat) as & _ )
88
88
. collect ( )
89
89
} ;
@@ -113,8 +113,8 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
113
113
}
114
114
}
115
115
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.
118
118
pub ( crate ) fn set_useful ( & self ) {
119
119
self . useful . set ( true )
120
120
}
@@ -132,19 +132,19 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
132
132
}
133
133
}
134
134
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
140
140
}
141
- fn collect_redundant_spans ( & self , spans : & mut Vec < Cx :: Span > ) {
141
+ fn collect_redundant_subpatterns < ' a > ( & ' a self , subpats : & mut Vec < & ' a Self > ) {
142
142
// We don't look at subpatterns if we already reported the whole pattern as redundant.
143
143
if !self . is_useful ( ) {
144
- spans . push ( self . span . clone ( ) ) ;
144
+ subpats . push ( self ) ;
145
145
} else {
146
146
for p in self . iter_fields ( ) {
147
- p. collect_redundant_spans ( spans ) ;
147
+ p. collect_redundant_subpatterns ( subpats ) ;
148
148
}
149
149
}
150
150
}
0 commit comments