@@ -528,60 +528,31 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
528
528
let tcx = pcx. fcx . ccx . tcx ;
529
529
530
530
let def = tcx. def_map . borrow ( ) . get ( & pat. id ) . unwrap ( ) . full_def ( ) ;
531
- let ( adt_def, variant) = match def {
532
- def:: DefTrait ( _) => {
531
+ let variant = match fcx. def_struct_variant ( def) {
532
+ Some ( ( _, variant) ) => variant,
533
+ None => {
533
534
let name = pprust:: path_to_string ( path) ;
534
- span_err ! ( tcx. sess, pat. span, E0168 ,
535
- "use of trait `{}` in a struct pattern ", name) ;
535
+ span_err ! ( tcx. sess, pat. span, E0163 ,
536
+ " `{}` does not name a struct or a struct variant ", name) ;
536
537
fcx. write_error ( pat. id ) ;
537
538
538
539
for field in fields {
539
- check_pat ( pcx, & * field. node . pat , tcx. types . err ) ;
540
+ check_pat ( pcx, & field. node . pat , tcx. types . err ) ;
540
541
}
541
542
return ;
542
- } ,
543
- _ => {
544
- let def_type = tcx. lookup_item_type ( def. def_id ( ) ) ;
545
- match def_type. ty . sty {
546
- ty:: TyStruct ( struct_def, _) =>
547
- ( struct_def, struct_def. struct_variant ( ) ) ,
548
- ty:: TyEnum ( enum_def, _)
549
- if def == def:: DefVariant ( enum_def. did , def. def_id ( ) , true ) =>
550
- ( enum_def, enum_def. variant_of_def ( def) ) ,
551
- _ => {
552
- let name = pprust:: path_to_string ( path) ;
553
- span_err ! ( tcx. sess, pat. span, E0163 ,
554
- "`{}` does not name a struct or a struct variant" , name) ;
555
- fcx. write_error ( pat. id ) ;
556
-
557
- for field in fields {
558
- check_pat ( pcx, & * field. node . pat , tcx. types . err ) ;
559
- }
560
- return ;
561
- }
562
- }
563
543
}
564
544
} ;
565
545
566
- instantiate_path ( pcx. fcx ,
567
- & path. segments ,
568
- adt_def. type_scheme ( tcx) ,
569
- & adt_def. predicates ( tcx) ,
570
- None ,
571
- def,
572
- pat. span ,
573
- pat. id ) ;
574
-
575
- let pat_ty = fcx. node_ty ( pat. id ) ;
546
+ let pat_ty = pcx. fcx . instantiate_type ( def. def_id ( ) , path) ;
547
+ let item_substs = match pat_ty. sty {
548
+ ty:: TyStruct ( _, substs) | ty:: TyEnum ( _, substs) => substs,
549
+ _ => tcx. sess . span_bug ( pat. span , "struct variant is not an ADT" )
550
+ } ;
576
551
demand:: eqtype ( fcx, pat. span , expected, pat_ty) ;
577
-
578
- let item_substs = fcx
579
- . item_substs ( )
580
- . get ( & pat. id )
581
- . map ( |substs| substs. substs . clone ( ) )
582
- . unwrap_or_else ( || Substs :: empty ( ) ) ;
583
-
584
552
check_struct_pat_fields ( pcx, pat. span , fields, variant, & item_substs, etc) ;
553
+
554
+ fcx. write_ty ( pat. id , pat_ty) ;
555
+ fcx. write_substs ( pat. id , ty:: ItemSubsts { substs : item_substs. clone ( ) } ) ;
585
556
}
586
557
587
558
pub fn check_pat_enum < ' a , ' tcx > ( pcx : & pat_ctxt < ' a , ' tcx > ,
0 commit comments