@@ -382,26 +382,43 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
382382
383383 // Find the variant that was specified.
384384 match tcx. def_map . borrow ( ) . find ( & pat_id) {
385- Some ( & def:: DefVariant ( found_enum_id, variant_id, _ ) )
385+ Some ( & def:: DefVariant ( found_enum_id, variant_id, true ) )
386386 if found_enum_id == enum_id => {
387387 // Get the struct fields from this struct-like enum variant.
388- let class_fields = ty:: lookup_struct_fields ( tcx, variant_id) ;
389-
390- check_struct_pat_fields ( pcx, span, fields, class_fields,
388+ let struct_fields = ty:: lookup_struct_fields ( tcx, variant_id) ;
389+ check_struct_pat_fields ( pcx, span, fields, struct_fields,
391390 variant_id, substitutions, etc) ;
391+ fcx. write_ty ( pat_id, expected) ;
392+ }
393+ Some ( & def:: DefVariant ( _, _, false ) ) => {
394+ let name = pprust:: path_to_string ( path) ;
395+ span_err ! ( tcx. sess, span, E0163 ,
396+ "`{}` does not name a struct variant" , name) ;
397+ fcx. write_error ( pat_id) ;
398+ }
399+ Some ( & def:: DefVariant ( _, _, true ) ) => {
400+ let name = pprust:: path_to_string ( path) ;
401+ span_err ! ( tcx. sess, span, E0164 ,
402+ "`{}` does not name a variant of the type being matched against" , name) ;
403+ fcx. write_error ( pat_id) ;
392404 }
393405 Some ( & def:: DefStruct ( ..) ) |
394- Some ( & def:: DefVariant ( ..) ) |
395406 Some ( & def:: DefTy ( ..) ) => {
396407 let name = pprust:: path_to_string ( path) ;
397408 span_err ! ( tcx. sess, span, E0028 ,
398- "mismatched types: expected `{}`, found `{}`" ,
399- fcx. infcx ( ) . ty_to_string ( expected ) , name ) ;
409+ "`{}` does not name a variant" , name ) ;
410+ fcx. write_error ( pat_id ) ;
400411 }
401412 _ => {
402413 tcx. sess . span_bug ( span, "resolve didn't write in variant" ) ;
403414 }
404415 }
416+
417+ if ty:: type_is_error ( fcx. node_ty ( pat_id) ) {
418+ for field in fields. iter ( ) {
419+ check_pat ( pcx, & * field. pat , ty:: mk_err ( ) ) ;
420+ }
421+ }
405422}
406423
407424// Pattern checking is top-down rather than bottom-up so that bindings get
0 commit comments