@@ -6,7 +6,7 @@ use std::fmt;
6
6
use smallvec:: { smallvec, SmallVec } ;
7
7
8
8
use crate :: constructor:: { Constructor , Slice , SliceKind } ;
9
- use crate :: { Captures , TypeCx } ;
9
+ use crate :: TypeCx ;
10
10
11
11
use self :: Constructor :: * ;
12
12
@@ -21,9 +21,9 @@ use self::Constructor::*;
21
21
/// This happens if a private or `non_exhaustive` field is uninhabited, because the code mustn't
22
22
/// observe that it is uninhabited. In that case that field is not included in `fields`. Care must
23
23
/// be taken when converting to/from `thir::Pat`.
24
- pub struct DeconstructedPat < ' p , Cx : TypeCx > {
24
+ pub struct DeconstructedPat < Cx : TypeCx > {
25
25
ctor : Constructor < Cx > ,
26
- fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
26
+ fields : Vec < DeconstructedPat < Cx > > ,
27
27
ty : Cx :: Ty ,
28
28
/// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
29
29
/// correspond to a user-supplied pattern.
@@ -32,14 +32,20 @@ pub struct DeconstructedPat<'p, Cx: TypeCx> {
32
32
useful : Cell < bool > ,
33
33
}
34
34
35
- impl < ' p , Cx : TypeCx > DeconstructedPat < ' p , Cx > {
35
+ impl < Cx : TypeCx > DeconstructedPat < Cx > {
36
36
pub fn wildcard ( ty : Cx :: Ty ) -> Self {
37
- DeconstructedPat { ctor : Wildcard , fields : & [ ] , ty, data : None , useful : Cell :: new ( false ) }
37
+ DeconstructedPat {
38
+ ctor : Wildcard ,
39
+ fields : Vec :: new ( ) ,
40
+ ty,
41
+ data : None ,
42
+ useful : Cell :: new ( false ) ,
43
+ }
38
44
}
39
45
40
46
pub fn new (
41
47
ctor : Constructor < Cx > ,
42
- fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
48
+ fields : Vec < DeconstructedPat < Cx > > ,
43
49
ty : Cx :: Ty ,
44
50
data : Cx :: PatData ,
45
51
) -> Self {
@@ -62,17 +68,17 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
62
68
self . data . as_ref ( )
63
69
}
64
70
65
- pub fn iter_fields ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Captures < ' _ > {
71
+ pub fn iter_fields < ' a > ( & ' a self ) -> impl Iterator < Item = & ' a DeconstructedPat < Cx > > {
66
72
self . fields . iter ( )
67
73
}
68
74
69
75
/// Specialize this pattern with a constructor.
70
76
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
71
- pub ( crate ) fn specialize (
72
- & self ,
77
+ pub ( crate ) fn specialize < ' a > (
78
+ & ' a self ,
73
79
other_ctor : & Constructor < Cx > ,
74
80
ctor_arity : usize ,
75
- ) -> SmallVec < [ PatOrWild < ' p , Cx > ; 2 ] > {
81
+ ) -> SmallVec < [ PatOrWild < ' a , Cx > ; 2 ] > {
76
82
let wildcard_sub_tys = || ( 0 ..ctor_arity) . map ( |_| PatOrWild :: Wild ) . collect ( ) ;
77
83
match ( & self . ctor , other_ctor) {
78
84
// Return a wildcard for each field of `other_ctor`.
@@ -139,7 +145,7 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
139
145
}
140
146
141
147
/// This is best effort and not good enough for a `Display` impl.
142
- impl < ' p , Cx : TypeCx > fmt:: Debug for DeconstructedPat < ' p , Cx > {
148
+ impl < Cx : TypeCx > fmt:: Debug for DeconstructedPat < Cx > {
143
149
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
144
150
let pat = self ;
145
151
let mut first = true ;
@@ -221,7 +227,7 @@ pub(crate) enum PatOrWild<'p, Cx: TypeCx> {
221
227
/// A non-user-provided wildcard, created during specialization.
222
228
Wild ,
223
229
/// A user-provided pattern.
224
- Pat ( & ' p DeconstructedPat < ' p , Cx > ) ,
230
+ Pat ( & ' p DeconstructedPat < Cx > ) ,
225
231
}
226
232
227
233
impl < ' p , Cx : TypeCx > Clone for PatOrWild < ' p , Cx > {
@@ -236,7 +242,7 @@ impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
236
242
impl < ' p , Cx : TypeCx > Copy for PatOrWild < ' p , Cx > { }
237
243
238
244
impl < ' p , Cx : TypeCx > PatOrWild < ' p , Cx > {
239
- pub ( crate ) fn as_pat ( & self ) -> Option < & ' p DeconstructedPat < ' p , Cx > > {
245
+ pub ( crate ) fn as_pat ( & self ) -> Option < & ' p DeconstructedPat < Cx > > {
240
246
match self {
241
247
PatOrWild :: Wild => None ,
242
248
PatOrWild :: Pat ( pat) => Some ( pat) ,
0 commit comments