@@ -736,15 +736,16 @@ pub(crate) struct PlaceCtxt<'a, Cx: TypeCx> {
736736 #[ derivative( Debug = "ignore" ) ]
737737 pub ( crate ) mcx : MatchCtxt < ' a , Cx > ,
738738 /// Type of the place under investigation.
739- pub ( crate ) ty : Cx :: Ty ,
739+ #[ derivative( Clone ( clone_with = "Clone::clone" ) ) ] // See rust-derivative#90
740+ pub ( crate ) ty : & ' a Cx :: Ty ,
740741 /// Whether the place is the original scrutinee place, as opposed to a subplace of it.
741742 pub ( crate ) is_scrutinee : bool ,
742743}
743744
744745impl < ' a , Cx : TypeCx > PlaceCtxt < ' a , Cx > {
745746 /// A `PlaceCtxt` when code other than `is_useful` needs one.
746747 #[ cfg_attr( not( feature = "rustc" ) , allow( dead_code) ) ]
747- pub ( crate ) fn new_dummy ( mcx : MatchCtxt < ' a , Cx > , ty : Cx :: Ty ) -> Self {
748+ pub ( crate ) fn new_dummy ( mcx : MatchCtxt < ' a , Cx > , ty : & ' a Cx :: Ty ) -> Self {
748749 PlaceCtxt { mcx, ty, is_scrutinee : false }
749750 }
750751
@@ -1039,8 +1040,8 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10391040 matrix
10401041 }
10411042
1042- fn head_ty ( & self ) -> Option < Cx :: Ty > {
1043- self . place_ty . first ( ) . copied ( )
1043+ fn head_ty ( & self ) -> Option < & Cx :: Ty > {
1044+ self . place_ty . first ( )
10441045 }
10451046 fn column_count ( & self ) -> usize {
10461047 self . place_ty . len ( )
@@ -1074,7 +1075,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10741075 let ctor_sub_tys = pcx. ctor_sub_tys ( ctor) ;
10751076 let arity = ctor_sub_tys. len ( ) ;
10761077 let specialized_place_ty =
1077- ctor_sub_tys. iter ( ) . chain ( self . place_ty [ 1 ..] . iter ( ) ) . copied ( ) . collect ( ) ;
1078+ ctor_sub_tys. iter ( ) . chain ( self . place_ty [ 1 ..] . iter ( ) ) . cloned ( ) . collect ( ) ;
10781079 let ctor_sub_validity = self . place_validity [ 0 ] . specialize ( ctor) ;
10791080 let specialized_place_validity = std:: iter:: repeat ( ctor_sub_validity)
10801081 . take ( arity)
@@ -1230,7 +1231,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12301231 let len = self . 0 . len ( ) ;
12311232 let arity = ctor. arity ( pcx) ;
12321233 let fields = self . 0 . drain ( ( len - arity) ..) . rev ( ) . collect ( ) ;
1233- let pat = WitnessPat :: new ( ctor. clone ( ) , fields, pcx. ty ) ;
1234+ let pat = WitnessPat :: new ( ctor. clone ( ) , fields, pcx. ty . clone ( ) ) ;
12341235 self . 0 . push ( pat) ;
12351236 }
12361237}
@@ -1426,7 +1427,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14261427 return Ok ( WitnessMatrix :: empty ( ) ) ;
14271428 }
14281429
1429- let Some ( ty) = matrix. head_ty ( ) else {
1430+ let Some ( ty) = matrix. head_ty ( ) . cloned ( ) else {
14301431 // The base case: there are no columns in the matrix. We are morally pattern-matching on ().
14311432 // A row is useful iff it has no (unguarded) rows above it.
14321433 let mut useful = true ; // Whether the next row is useful.
@@ -1447,7 +1448,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14471448 } ;
14481449
14491450 debug ! ( "ty: {ty:?}" ) ;
1450- let pcx = & PlaceCtxt { mcx, ty, is_scrutinee : is_top_level } ;
1451+ let pcx = & PlaceCtxt { mcx, ty : & ty , is_scrutinee : is_top_level } ;
14511452
14521453 // Whether the place/column we are inspecting is known to contain valid data.
14531454 let place_validity = matrix. place_validity [ 0 ] ;
0 commit comments