1
1
//! As explained in [`crate::usefulness`], values and patterns are made from constructors applied to
2
2
//! fields. This file defines types that represent patterns in this way.
3
- use std:: cell:: Cell ;
4
3
use std:: fmt;
5
4
6
5
use smallvec:: { smallvec, SmallVec } ;
@@ -11,11 +10,8 @@ use crate::TypeCx;
11
10
use self :: Constructor :: * ;
12
11
13
12
/// Values and patterns can be represented as a constructor applied to some fields. This represents
14
- /// a pattern in this form.
15
- /// This also uses interior mutability to keep track of whether the pattern has been found reachable
16
- /// during analysis. For this reason they cannot be cloned.
17
- /// A `DeconstructedPat` will almost always come from user input; the only exception are some
18
- /// `Wildcard`s introduced during specialization.
13
+ /// a pattern in this form. A `DeconstructedPat` will almost always come from user input; the only
14
+ /// exception are some `Wildcard`s introduced during pattern lowering.
19
15
///
20
16
/// Note that the number of fields may not match the fields declared in the original struct/variant.
21
17
/// This happens if a private or `non_exhaustive` field is uninhabited, because the code mustn't
@@ -28,19 +24,11 @@ pub struct DeconstructedPat<Cx: TypeCx> {
28
24
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
29
25
/// correspond to a user-supplied pattern.
30
26
data : Option < Cx :: PatData > ,
31
- /// Whether removing this arm would change the behavior of the match expression.
32
- pub ( crate ) useful : Cell < bool > ,
33
27
}
34
28
35
29
impl < Cx : TypeCx > DeconstructedPat < Cx > {
36
30
pub fn wildcard ( ty : Cx :: Ty ) -> Self {
37
- DeconstructedPat {
38
- ctor : Wildcard ,
39
- fields : Vec :: new ( ) ,
40
- ty,
41
- data : None ,
42
- useful : Cell :: new ( false ) ,
43
- }
31
+ DeconstructedPat { ctor : Wildcard , fields : Vec :: new ( ) , ty, data : None }
44
32
}
45
33
46
34
pub fn new (
@@ -49,7 +37,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
49
37
ty : Cx :: Ty ,
50
38
data : Cx :: PatData ,
51
39
) -> Self {
52
- DeconstructedPat { ctor, fields, ty, data : Some ( data) , useful : Cell :: new ( false ) }
40
+ DeconstructedPat { ctor, fields, ty, data : Some ( data) }
53
41
}
54
42
55
43
pub ( crate ) fn is_or_pat ( & self ) -> bool {
@@ -107,12 +95,6 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
107
95
}
108
96
}
109
97
110
- /// We keep track for each pattern if it was ever useful during the analysis. This is used with
111
- /// `redundant_subpatterns` to report redundant subpatterns arising from or patterns.
112
- pub ( crate ) fn set_useful ( & self ) {
113
- self . useful . set ( true )
114
- }
115
-
116
98
/// Walk top-down and call `it` in each place where a pattern occurs
117
99
/// starting with the root pattern `walk` is called on. If `it` returns
118
100
/// false then we will descend no further but siblings will be processed.
@@ -267,12 +249,6 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
267
249
PatOrWild :: Pat ( pat) => pat. specialize ( other_ctor, ctor_arity) ,
268
250
}
269
251
}
270
-
271
- pub ( crate ) fn set_useful ( & self ) {
272
- if let PatOrWild :: Pat ( pat) = self {
273
- pat. set_useful ( )
274
- }
275
- }
276
252
}
277
253
278
254
impl < ' p , Cx : TypeCx > fmt:: Debug for PatOrWild < ' p , Cx > {
0 commit comments