@@ -1122,11 +1122,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1122
1122
} )
1123
1123
}
1124
1124
1125
- // FIXME(#19596) unbox `op`
1126
- pub fn cat_pattern ( & self ,
1127
- cmt : cmt < ' tcx > ,
1128
- pat : & ast:: Pat ,
1129
- op : |& MemCategorizationContext < ' t , TYPER > , cmt < ' tcx > , & ast:: Pat |)
1125
+ pub fn cat_pattern < F > ( & self , cmt : cmt < ' tcx > , pat : & ast:: Pat , mut op : F ) where
1126
+ F : FnMut ( & MemCategorizationContext < ' t , TYPER > , cmt < ' tcx > , & ast:: Pat ) ,
1127
+ {
1128
+ self . cat_pattern_ ( cmt, pat, & mut op)
1129
+ }
1130
+
1131
+ // FIXME(#19596) This is a workaround, but there should be a better way to do this
1132
+ fn cat_pattern_ < F > ( & self , cmt : cmt < ' tcx > , pat : & ast:: Pat , op : & mut F ) where
1133
+ F : FnMut ( & MemCategorizationContext < ' t , TYPER > , cmt < ' tcx > , & ast:: Pat ) ,
1130
1134
{
1131
1135
// Here, `cmt` is the categorization for the value being
1132
1136
// matched and pat is the pattern it is being matched against.
@@ -1177,7 +1181,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1177
1181
pat. id, pprust:: pat_to_string( pat) ,
1178
1182
cmt. repr( self . tcx( ) ) ) ;
1179
1183
1180
- op ( self , cmt. clone ( ) , pat) ;
1184
+ ( * op ) ( self , cmt. clone ( ) , pat) ;
1181
1185
1182
1186
let def_map = self . tcx ( ) . def_map . borrow ( ) ;
1183
1187
let opt_def = def_map. get ( & pat. id ) ;
@@ -1214,7 +1218,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1214
1218
pat, cmt. clone ( ) , subpat_ty,
1215
1219
InteriorField ( PositionalField ( i) ) ) ;
1216
1220
1217
- self . cat_pattern ( subcmt, & * * subpat, |x , y , z| op ( x , y , z ) ) ;
1221
+ self . cat_pattern_ ( subcmt, & * * subpat, op ) ;
1218
1222
}
1219
1223
}
1220
1224
Some ( & def:: DefStruct ( ..) ) => {
@@ -1224,13 +1228,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1224
1228
self . cat_imm_interior (
1225
1229
pat, cmt. clone ( ) , subpat_ty,
1226
1230
InteriorField ( PositionalField ( i) ) ) ;
1227
- self . cat_pattern ( cmt_field, & * * subpat,
1228
- |x, y, z| op ( x, y, z) ) ;
1231
+ self . cat_pattern_ ( cmt_field, & * * subpat, op) ;
1229
1232
}
1230
1233
}
1231
1234
Some ( & def:: DefConst ( ..) ) => {
1232
1235
for subpat in subpats. iter ( ) {
1233
- self . cat_pattern ( cmt. clone ( ) , & * * subpat, |x , y , z| op ( x , y , z ) ) ;
1236
+ self . cat_pattern_ ( cmt. clone ( ) , & * * subpat, op ) ;
1234
1237
}
1235
1238
}
1236
1239
_ => {
@@ -1242,7 +1245,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1242
1245
}
1243
1246
1244
1247
ast:: PatIdent ( _, _, Some ( ref subpat) ) => {
1245
- self . cat_pattern ( cmt, & * * subpat, op) ;
1248
+ self . cat_pattern_ ( cmt, & * * subpat, op) ;
1246
1249
}
1247
1250
1248
1251
ast:: PatIdent ( _, _, None ) => {
@@ -1254,7 +1257,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1254
1257
for fp in field_pats. iter ( ) {
1255
1258
let field_ty = self . pat_ty ( & * fp. node . pat ) ; // see (*2)
1256
1259
let cmt_field = self . cat_field ( pat, cmt. clone ( ) , fp. node . ident . name , field_ty) ;
1257
- self . cat_pattern ( cmt_field, & * fp. node . pat , |x , y , z| op ( x , y , z ) ) ;
1260
+ self . cat_pattern_ ( cmt_field, & * fp. node . pat , op ) ;
1258
1261
}
1259
1262
}
1260
1263
@@ -1266,29 +1269,28 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1266
1269
self . cat_imm_interior (
1267
1270
pat, cmt. clone ( ) , subpat_ty,
1268
1271
InteriorField ( PositionalField ( i) ) ) ;
1269
- self . cat_pattern ( subcmt, & * * subpat, |x , y , z| op ( x , y , z ) ) ;
1272
+ self . cat_pattern_ ( subcmt, & * * subpat, op ) ;
1270
1273
}
1271
1274
}
1272
1275
1273
1276
ast:: PatBox ( ref subpat) | ast:: PatRegion ( ref subpat) => {
1274
1277
// @p1, ~p1, ref p1
1275
1278
let subcmt = self . cat_deref ( pat, cmt, 0 , false ) ;
1276
- self . cat_pattern ( subcmt, & * * subpat, op) ;
1279
+ self . cat_pattern_ ( subcmt, & * * subpat, op) ;
1277
1280
}
1278
1281
1279
1282
ast:: PatVec ( ref before, ref slice, ref after) => {
1280
1283
let elt_cmt = self . cat_index ( pat, self . deref_vec ( pat, cmt) ) ;
1281
1284
for before_pat in before. iter ( ) {
1282
- self . cat_pattern ( elt_cmt. clone ( ) , & * * before_pat,
1283
- |x, y, z| op ( x, y, z) ) ;
1285
+ self . cat_pattern_ ( elt_cmt. clone ( ) , & * * before_pat, op) ;
1284
1286
}
1285
1287
for slice_pat in slice. iter ( ) {
1286
1288
let slice_ty = self . pat_ty ( & * * slice_pat) ;
1287
1289
let slice_cmt = self . cat_rvalue_node ( pat. id ( ) , pat. span ( ) , slice_ty) ;
1288
- self . cat_pattern ( slice_cmt, & * * slice_pat, |x , y , z| op ( x , y , z ) ) ;
1290
+ self . cat_pattern_ ( slice_cmt, & * * slice_pat, op ) ;
1289
1291
}
1290
1292
for after_pat in after. iter ( ) {
1291
- self . cat_pattern ( elt_cmt. clone ( ) , & * * after_pat, |x , y , z| op ( x , y , z ) ) ;
1293
+ self . cat_pattern_ ( elt_cmt. clone ( ) , & * * after_pat, op ) ;
1292
1294
}
1293
1295
}
1294
1296
0 commit comments