@@ -736,15 +736,16 @@ pub(crate) struct PlaceCtxt<'a, Cx: TypeCx> {
736
736
#[ derivative( Debug = "ignore" ) ]
737
737
pub ( crate ) mcx : MatchCtxt < ' a , Cx > ,
738
738
/// 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 ,
740
741
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
741
742
pub ( crate ) is_scrutinee : bool ,
742
743
}
743
744
744
745
impl < ' a , Cx : TypeCx > PlaceCtxt < ' a , Cx > {
745
746
/// A `PlaceCtxt` when code other than `is_useful` needs one.
746
747
#[ 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 {
748
749
PlaceCtxt { mcx, ty, is_scrutinee : false }
749
750
}
750
751
@@ -1039,8 +1040,8 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1039
1040
matrix
1040
1041
}
1041
1042
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 ( )
1044
1045
}
1045
1046
fn column_count ( & self ) -> usize {
1046
1047
self . place_ty . len ( )
@@ -1074,7 +1075,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1074
1075
let ctor_sub_tys = pcx. ctor_sub_tys ( ctor) ;
1075
1076
let arity = ctor_sub_tys. len ( ) ;
1076
1077
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 ( ) ;
1078
1079
let ctor_sub_validity = self . place_validity [ 0 ] . specialize ( ctor) ;
1079
1080
let specialized_place_validity = std:: iter:: repeat ( ctor_sub_validity)
1080
1081
. take ( arity)
@@ -1230,7 +1231,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
1230
1231
let len = self . 0 . len ( ) ;
1231
1232
let arity = ctor. arity ( pcx) ;
1232
1233
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 ( ) ) ;
1234
1235
self . 0 . push ( pat) ;
1235
1236
}
1236
1237
}
@@ -1435,7 +1436,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1435
1436
return Ok ( WitnessMatrix :: empty ( ) ) ;
1436
1437
}
1437
1438
1438
- let Some ( ty) = matrix. head_ty ( ) else {
1439
+ let Some ( ty) = matrix. head_ty ( ) . cloned ( ) else {
1439
1440
// The base case: there are no columns in the matrix. We are morally pattern-matching on ().
1440
1441
// A row is useful iff it has no (unguarded) rows above it.
1441
1442
let mut useful = true ; // Whether the next row is useful.
@@ -1456,7 +1457,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1456
1457
} ;
1457
1458
1458
1459
debug ! ( "ty: {ty:?}" ) ;
1459
- let pcx = & PlaceCtxt { mcx, ty, is_scrutinee : is_top_level } ;
1460
+ let pcx = & PlaceCtxt { mcx, ty : & ty , is_scrutinee : is_top_level } ;
1460
1461
1461
1462
// Whether the place/column we are inspecting is known to contain valid data.
1462
1463
let place_validity = matrix. place_validity [ 0 ] ;
0 commit comments