@@ -80,6 +80,7 @@ use ty::adjustment;
80
80
use ty:: { self , Ty , TyCtxt } ;
81
81
82
82
use hir:: { MutImmutable , MutMutable , PatKind } ;
83
+ use hir:: pat_util:: EnumerateAndAdjustIterator ;
83
84
use hir;
84
85
use syntax:: ast;
85
86
use syntax:: codemap:: Span ;
@@ -1225,14 +1226,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1225
1226
// _
1226
1227
}
1227
1228
1228
- PatKind :: TupleStruct ( _, None ) => {
1229
- // variant(..)
1230
- }
1231
- PatKind :: TupleStruct ( _, Some ( ref subpats) ) => {
1229
+ PatKind :: TupleStruct ( _, ref subpats, ddpos) => {
1232
1230
match opt_def {
1233
- Some ( Def :: Variant ( .. ) ) => {
1231
+ Some ( Def :: Variant ( enum_def , def_id ) ) => {
1234
1232
// variant(x, y, z)
1235
- for ( i, subpat) in subpats. iter ( ) . enumerate ( ) {
1233
+ let expected_len = self . tcx ( ) . lookup_adt_def ( enum_def)
1234
+ . variant_with_id ( def_id) . fields . len ( ) ;
1235
+ for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1236
1236
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1237
1237
1238
1238
let subcmt =
@@ -1244,7 +1244,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1244
1244
}
1245
1245
}
1246
1246
Some ( Def :: Struct ( ..) ) => {
1247
- for ( i, subpat) in subpats. iter ( ) . enumerate ( ) {
1247
+ let expected_len = match self . pat_ty ( & pat) {
1248
+ Ok ( & ty:: TyS { sty : ty:: TyStruct ( adt_def, _) , ..} ) => {
1249
+ adt_def. struct_variant ( ) . fields . len ( )
1250
+ }
1251
+ ref ty => {
1252
+ span_bug ! ( pat. span, "tuple struct pattern unexpected type {:?}" , ty) ;
1253
+ }
1254
+ } ;
1255
+
1256
+ for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1248
1257
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1249
1258
let cmt_field =
1250
1259
self . cat_imm_interior (
@@ -1284,9 +1293,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1284
1293
}
1285
1294
}
1286
1295
1287
- PatKind :: Tup ( ref subpats) => {
1296
+ PatKind :: Tuple ( ref subpats, ddpos ) => {
1288
1297
// (p1, ..., pN)
1289
- for ( i, subpat) in subpats. iter ( ) . enumerate ( ) {
1298
+ let expected_len = match self . pat_ty ( & pat) {
1299
+ Ok ( & ty:: TyS { sty : ty:: TyTuple ( ref tys) , ..} ) => tys. len ( ) ,
1300
+ ref ty => span_bug ! ( pat. span, "tuple pattern unexpected type {:?}" , ty) ,
1301
+ } ;
1302
+ for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( expected_len, ddpos) {
1290
1303
let subpat_ty = self . pat_ty ( & subpat) ?; // see (*2)
1291
1304
let subcmt =
1292
1305
self . cat_imm_interior (
0 commit comments