@@ -139,7 +139,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
139
139
if pat_is_resolved_const ( & tcx. def_map . borrow ( ) , pat) => {
140
140
if let hir:: PatEnum ( ref path, ref subpats) = pat. node {
141
141
if !( subpats. is_some ( ) && subpats. as_ref ( ) . unwrap ( ) . is_empty ( ) ) {
142
- bad_struct_kind_err ( tcx. sess , pat. span , path) ;
142
+ bad_struct_kind_err ( tcx. sess , pat. span , path, false ) ;
143
143
return ;
144
144
}
145
145
}
@@ -581,9 +581,9 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
581
581
}
582
582
583
583
// This function exists due to the warning "diagnostic code E0164 already used"
584
- fn bad_struct_kind_err ( sess : & Session , span : Span , path : & hir:: Path ) {
584
+ fn bad_struct_kind_err ( sess : & Session , span : Span , path : & hir:: Path , is_warning : bool ) {
585
585
let name = pprust:: path_to_string ( path) ;
586
- span_err ! ( sess, span, E0164 ,
586
+ span_err_or_warn ! ( is_warning , sess, span, E0164 ,
587
587
"`{}` does not name a tuple variant or a tuple struct" , name) ;
588
588
}
589
589
@@ -634,8 +634,8 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
634
634
path_scheme, & ctor_predicates,
635
635
opt_ty, def, pat. span , pat. id ) ;
636
636
637
- let report_bad_struct_kind = || {
638
- bad_struct_kind_err ( tcx. sess , pat. span , path) ;
637
+ let report_bad_struct_kind = |is_warning | {
638
+ bad_struct_kind_err ( tcx. sess , pat. span , path, is_warning ) ;
639
639
fcx. write_error ( pat. id ) ;
640
640
641
641
if let Some ( subpats) = subpats {
@@ -650,7 +650,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
650
650
// function uses checks specific to structs and enums.
651
651
if path_res. depth != 0 {
652
652
if is_tuple_struct_pat {
653
- report_bad_struct_kind ( ) ;
653
+ report_bad_struct_kind ( false ) ;
654
654
} else {
655
655
let pat_ty = fcx. node_ty ( pat. id ) ;
656
656
demand:: suptype ( fcx, pat. span , expected, pat_ty) ;
@@ -668,8 +668,13 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
668
668
{
669
669
let variant = enum_def. variant_of_def ( def) ;
670
670
if is_tuple_struct_pat && variant. kind ( ) != ty:: VariantKind :: Tuple {
671
- report_bad_struct_kind ( ) ;
672
- return ;
671
+ // Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
672
+ // is allowed for backward compatibility.
673
+ let is_special_case = variant. kind ( ) == ty:: VariantKind :: Unit ;
674
+ report_bad_struct_kind ( is_special_case) ;
675
+ if !is_special_case {
676
+ return
677
+ }
673
678
}
674
679
( variant. fields
675
680
. iter ( )
@@ -682,7 +687,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
682
687
ty:: TyStruct ( struct_def, expected_substs) => {
683
688
let variant = struct_def. struct_variant ( ) ;
684
689
if is_tuple_struct_pat && variant. kind ( ) != ty:: VariantKind :: Tuple {
685
- report_bad_struct_kind ( ) ;
690
+ report_bad_struct_kind ( false ) ;
686
691
return ;
687
692
}
688
693
( variant. fields
@@ -694,7 +699,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
694
699
"struct" )
695
700
}
696
701
_ => {
697
- report_bad_struct_kind ( ) ;
702
+ report_bad_struct_kind ( false ) ;
698
703
return ;
699
704
}
700
705
} ;
0 commit comments