@@ -361,6 +361,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361
361
PatKind :: Expr ( PatExpr { kind : PatExprKind :: Path ( qpath) , hir_id, span } ) => {
362
362
Some { 0 : & self . check_pat_path ( * hir_id, pat. hir_id , * span, qpath, & ti) }
363
363
}
364
+ PatKind :: Struct ( ref qpath, fields, has_rest_pat) => {
365
+ Some { 0 : & self . check_pat_struct ( pat, qpath, fields, has_rest_pat) }
366
+ }
364
367
_ => None ,
365
368
} ;
366
369
let adjust_mode = self . calc_adjust_mode ( pat, resolved_pat. and_then ( |r| r. path_res ) ) ;
@@ -393,9 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393
396
PatKind :: TupleStruct ( ref qpath, subpats, ddpos) => {
394
397
self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, pat_info)
395
398
}
396
- PatKind :: Struct ( ref qpath, fields, has_rest_pat) => {
397
- self . check_pat_struct ( pat, qpath, fields, has_rest_pat, expected, pat_info)
398
- }
399
+ PatKind :: Struct ( ..) => ( resolved_pat. unwrap ( ) . check ) ( expected, pat_info) ,
399
400
PatKind :: Guard ( pat, cond) => {
400
401
self . check_pat ( pat, expected, pat_info) ;
401
402
self . check_expr_has_type_or_error ( cond, self . tcx . types . bool , |_| { } ) ;
@@ -1229,29 +1230,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1229
1230
qpath : & hir:: QPath < ' tcx > ,
1230
1231
fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
1231
1232
has_rest_pat : bool ,
1232
- expected : Ty < ' tcx > ,
1233
- pat_info : PatInfo < ' tcx > ,
1234
- ) -> Ty < ' tcx > {
1233
+ ) -> ResolvedPat < impl Fn ( Ty < ' tcx > , PatInfo < ' tcx > ) -> Ty < ' tcx > > {
1235
1234
// Resolve the path and check the definition for errors.
1236
- let ( variant, pat_ty) = match self . check_struct_path ( qpath, pat. hir_id ) {
1237
- Ok ( data) => data,
1238
- Err ( guar) => {
1239
- let err = Ty :: new_error ( self . tcx , guar) ;
1240
- for field in fields {
1241
- self . check_pat ( field. pat , err, pat_info) ;
1235
+ let variant_and_pat_ty = self . check_struct_path ( qpath, pat. hir_id ) ;
1236
+
1237
+ let check = move |expected : Ty < ' tcx > , pat_info : PatInfo < ' tcx > | -> Ty < ' tcx > {
1238
+ let ( variant, pat_ty) = match variant_and_pat_ty {
1239
+ Ok ( data) => data,
1240
+ Err ( guar) => {
1241
+ let err = Ty :: new_error ( self . tcx , guar) ;
1242
+ for field in fields {
1243
+ self . check_pat ( field. pat , err, pat_info) ;
1244
+ }
1245
+ return err;
1242
1246
}
1243
- return err;
1247
+ } ;
1248
+
1249
+ // Type-check the path.
1250
+ let _ = self . demand_eqtype_pat ( pat. span , expected, pat_ty, & pat_info. top_info ) ;
1251
+
1252
+ // Type-check subpatterns.
1253
+ match self . check_struct_pat_fields ( pat_ty, pat, variant, fields, has_rest_pat, pat_info)
1254
+ {
1255
+ Ok ( ( ) ) => pat_ty,
1256
+ Err ( guar) => Ty :: new_error ( self . tcx , guar) ,
1244
1257
}
1245
1258
} ;
1246
1259
1247
- // Type-check the path.
1248
- let _ = self . demand_eqtype_pat ( pat. span , expected, pat_ty, & pat_info. top_info ) ;
1249
-
1250
- // Type-check subpatterns.
1251
- match self . check_struct_pat_fields ( pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
1252
- Ok ( ( ) ) => pat_ty,
1253
- Err ( guar) => Ty :: new_error ( self . tcx , guar) ,
1254
- }
1260
+ ResolvedPat { path_res : None , check }
1255
1261
}
1256
1262
1257
1263
fn check_pat_path (
0 commit comments