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,7 @@ use crate::{Captures, 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 always come from user input.
19
14
///
20
15
/// Note that the number of fields may not match the fields declared in the original struct/variant.
21
16
/// This happens if a private or `non_exhaustive` field is uninhabited, because the code mustn't
@@ -28,13 +23,11 @@ pub struct DeconstructedPat<'p, Cx: TypeCx> {
28
23
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
29
24
/// correspond to a user-supplied pattern.
30
25
data : Option < Cx :: PatData > ,
31
- /// Whether removing this arm would change the behavior of the match expression.
32
- pub ( crate ) useful : Cell < bool > ,
33
26
}
34
27
35
28
impl < ' p , Cx : TypeCx > DeconstructedPat < ' p , Cx > {
36
29
pub fn wildcard ( ty : Cx :: Ty ) -> Self {
37
- DeconstructedPat { ctor : Wildcard , fields : & [ ] , ty, data : None , useful : Cell :: new ( false ) }
30
+ DeconstructedPat { ctor : Wildcard , fields : & [ ] , ty, data : None }
38
31
}
39
32
40
33
pub fn new (
@@ -43,7 +36,7 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
43
36
ty : Cx :: Ty ,
44
37
data : Cx :: PatData ,
45
38
) -> Self {
46
- DeconstructedPat { ctor, fields, ty, data : Some ( data) , useful : Cell :: new ( false ) }
39
+ DeconstructedPat { ctor, fields, ty, data : Some ( data) }
47
40
}
48
41
49
42
pub ( crate ) fn is_or_pat ( & self ) -> bool {
@@ -101,12 +94,6 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
101
94
}
102
95
}
103
96
104
- /// We keep track for each pattern if it was ever useful during the analysis. This is used with
105
- /// `redundant_subpatterns` to report redundant subpatterns arising from or patterns.
106
- pub ( crate ) fn set_useful ( & self ) {
107
- self . useful . set ( true )
108
- }
109
-
110
97
/// Walk top-down and call `it` in each place where a pattern occurs
111
98
/// starting with the root pattern `walk` is called on. If `it` returns
112
99
/// false then we will descend no further but siblings will be processed.
@@ -261,12 +248,6 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
261
248
PatOrWild :: Pat ( pat) => pat. specialize ( other_ctor, ctor_arity) ,
262
249
}
263
250
}
264
-
265
- pub ( crate ) fn set_useful ( & self ) {
266
- if let PatOrWild :: Pat ( pat) = self {
267
- pat. set_useful ( )
268
- }
269
- }
270
251
}
271
252
272
253
impl < ' p , Cx : TypeCx > fmt:: Debug for PatOrWild < ' p , Cx > {
0 commit comments