@@ -6,7 +6,7 @@ use std::fmt;
66use smallvec:: { smallvec, SmallVec } ;
77
88use crate :: constructor:: { Constructor , Slice , SliceKind } ;
9- use crate :: { Captures , TypeCx } ;
9+ use crate :: TypeCx ;
1010
1111use self :: Constructor :: * ;
1212
@@ -21,9 +21,9 @@ use self::Constructor::*;
2121/// This happens if a private or `non_exhaustive` field is uninhabited, because the code mustn't
2222/// observe that it is uninhabited. In that case that field is not included in `fields`. Care must
2323/// be taken when converting to/from `thir::Pat`.
24- pub struct DeconstructedPat < ' p , Cx : TypeCx > {
24+ pub struct DeconstructedPat < Cx : TypeCx > {
2525 ctor : Constructor < Cx > ,
26- fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
26+ fields : Vec < DeconstructedPat < Cx > > ,
2727 ty : Cx :: Ty ,
2828 /// Extra data to store in a pattern. `None` if the pattern is a wildcard that does not
2929 /// correspond to a user-supplied pattern.
@@ -32,14 +32,20 @@ pub struct DeconstructedPat<'p, Cx: TypeCx> {
3232 useful : Cell < bool > ,
3333}
3434
35- impl < ' p , Cx : TypeCx > DeconstructedPat < ' p , Cx > {
35+ impl < Cx : TypeCx > DeconstructedPat < Cx > {
3636 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+ }
3844 }
3945
4046 pub fn new (
4147 ctor : Constructor < Cx > ,
42- fields : & ' p [ DeconstructedPat < ' p , Cx > ] ,
48+ fields : Vec < DeconstructedPat < Cx > > ,
4349 ty : Cx :: Ty ,
4450 data : Cx :: PatData ,
4551 ) -> Self {
@@ -62,17 +68,17 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
6268 self . data . as_ref ( )
6369 }
6470
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 > > {
6672 self . fields . iter ( )
6773 }
6874
6975 /// Specialize this pattern with a constructor.
7076 /// `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 ,
7379 other_ctor : & Constructor < Cx > ,
7480 ctor_arity : usize ,
75- ) -> SmallVec < [ PatOrWild < ' p , Cx > ; 2 ] > {
81+ ) -> SmallVec < [ PatOrWild < ' a , Cx > ; 2 ] > {
7682 let wildcard_sub_tys = || ( 0 ..ctor_arity) . map ( |_| PatOrWild :: Wild ) . collect ( ) ;
7783 match ( & self . ctor , other_ctor) {
7884 // Return a wildcard for each field of `other_ctor`.
@@ -139,7 +145,7 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
139145}
140146
141147/// 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 > {
143149 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
144150 let pat = self ;
145151 let mut first = true ;
@@ -221,7 +227,7 @@ pub(crate) enum PatOrWild<'p, Cx: TypeCx> {
221227 /// A non-user-provided wildcard, created during specialization.
222228 Wild ,
223229 /// A user-provided pattern.
224- Pat ( & ' p DeconstructedPat < ' p , Cx > ) ,
230+ Pat ( & ' p DeconstructedPat < Cx > ) ,
225231}
226232
227233impl < ' p , Cx : TypeCx > Clone for PatOrWild < ' p , Cx > {
@@ -236,7 +242,7 @@ impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
236242impl < ' p , Cx : TypeCx > Copy for PatOrWild < ' p , Cx > { }
237243
238244impl < ' 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 > > {
240246 match self {
241247 PatOrWild :: Wild => None ,
242248 PatOrWild :: Pat ( pat) => Some ( pat) ,
0 commit comments