@@ -181,8 +181,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
181181 self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, def_bm, ti)
182182 }
183183 PatKind :: Path ( _) => self . check_pat_path ( pat, path_res. unwrap ( ) , expected, ti) ,
184- PatKind :: Struct ( ref qpath, fields, etc ) => {
185- self . check_pat_struct ( pat, qpath, fields, etc , expected, def_bm, ti)
184+ PatKind :: Struct ( ref qpath, fields, has_rest_pat ) => {
185+ self . check_pat_struct ( pat, qpath, fields, has_rest_pat , expected, def_bm, ti)
186186 }
187187 PatKind :: Or ( pats) => {
188188 let parent_pat = Some ( pat) ;
@@ -712,7 +712,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
712712 pat : & ' tcx Pat < ' tcx > ,
713713 qpath : & hir:: QPath < ' _ > ,
714714 fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
715- etc : bool ,
715+ has_rest_pat : bool ,
716716 expected : Ty < ' tcx > ,
717717 def_bm : BindingMode ,
718718 ti : TopInfo < ' tcx > ,
@@ -734,7 +734,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
734734 self . demand_eqtype_pat ( pat. span , expected, pat_ty, ti) ;
735735
736736 // Type-check subpatterns.
737- if self . check_struct_pat_fields ( pat_ty, pat, variant, fields, etc , def_bm, ti) {
737+ if self . check_struct_pat_fields ( pat_ty, & pat, variant, fields, has_rest_pat , def_bm, ti) {
738738 pat_ty
739739 } else {
740740 self . tcx . ty_error ( )
@@ -1216,7 +1216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12161216 pat : & ' tcx Pat < ' tcx > ,
12171217 variant : & ' tcx ty:: VariantDef ,
12181218 fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
1219- etc : bool ,
1219+ has_rest_pat : bool ,
12201220 def_bm : BindingMode ,
12211221 ti : TopInfo < ' tcx > ,
12221222 ) -> bool {
@@ -1290,7 +1290,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12901290
12911291 // Require `..` if struct has non_exhaustive attribute.
12921292 let non_exhaustive = variant. is_field_list_non_exhaustive ( ) && !adt. did . is_local ( ) ;
1293- if non_exhaustive && !etc {
1293+ if non_exhaustive && !has_rest_pat {
12941294 self . error_foreign_non_exhaustive_spat ( pat, adt. variant_descr ( ) , fields. is_empty ( ) ) ;
12951295 }
12961296
@@ -1302,7 +1302,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13021302 . struct_span_err ( pat. span , "union patterns should have exactly one field" )
13031303 . emit ( ) ;
13041304 }
1305- if etc {
1305+ if has_rest_pat {
13061306 tcx. sess . struct_span_err ( pat. span , "`..` cannot be used in union patterns" ) . emit ( ) ;
13071307 }
13081308 } else if !unmentioned_fields. is_empty ( ) {
@@ -1313,9 +1313,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13131313 field. vis . is_accessible_from ( tcx. parent_module ( pat. hir_id ) . to_def_id ( ) , tcx)
13141314 } )
13151315 . collect ( ) ;
1316- if non_exhaustive {
1317- self . non_exhaustive_reachable_pattern ( pat, & accessible_unmentioned_fields, adt_ty)
1318- } else if !etc {
1316+
1317+ if !has_rest_pat {
13191318 if accessible_unmentioned_fields. is_empty ( ) {
13201319 unmentioned_err = Some ( self . error_no_accessible_fields ( pat, fields) ) ;
13211320 } else {
@@ -1326,6 +1325,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13261325 fields,
13271326 ) ) ;
13281327 }
1328+ } else if non_exhaustive && !accessible_unmentioned_fields. is_empty ( ) {
1329+ self . lint_non_exhaustive_omitted_patterns (
1330+ pat,
1331+ & accessible_unmentioned_fields,
1332+ adt_ty,
1333+ )
13291334 }
13301335 }
13311336 match ( inexistent_fields_err, unmentioned_err) {
@@ -1653,7 +1658,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16531658 /// is not exhaustive enough.
16541659 ///
16551660 /// Nb: the partner lint for enums lives in `compiler/rustc_mir_build/src/thir/pattern/usefulness.rs`.
1656- fn non_exhaustive_reachable_pattern (
1661+ fn lint_non_exhaustive_omitted_patterns (
16571662 & self ,
16581663 pat : & Pat < ' _ > ,
16591664 unmentioned_fields : & [ ( & ty:: FieldDef , Ident ) ] ,
0 commit comments