@@ -873,34 +873,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
873873 if etc {
874874 tcx. sess . span_err ( span, "`..` cannot be used in union patterns" ) ;
875875 }
876- } else if !etc {
877- if unmentioned_fields. len ( ) > 0 {
878- let field_names = if unmentioned_fields. len ( ) == 1 {
879- format ! ( "field `{}`" , unmentioned_fields[ 0 ] )
880- } else {
881- format ! ( "fields {}" ,
882- unmentioned_fields. iter( )
883- . map( |name| format!( "`{}`" , name) )
884- . collect:: <Vec <String >>( )
885- . join( ", " ) )
886- } ;
887- let mut diag = struct_span_err ! ( tcx. sess, span, E0027 ,
888- "pattern does not mention {}" ,
889- field_names) ;
890- diag. span_label ( span, format ! ( "missing {}" , field_names) ) ;
891- if variant. ctor_kind == CtorKind :: Fn {
892- diag. note ( "trying to match a tuple variant with a struct variant pattern" ) ;
893- }
894- if tcx. sess . teach ( & diag. get_code ( ) . unwrap ( ) ) {
895- diag. note (
896- "This error indicates that a pattern for a struct fails to specify a \
897- sub-pattern for every one of the struct's fields. Ensure that each field \
898- from the struct's definition is mentioned in the pattern, or use `..` to \
899- ignore unwanted fields."
900- ) ;
901- }
902- diag. emit ( ) ;
903- }
876+ } else if !etc && unmentioned_fields. len ( ) > 0 {
877+ self . error_unmentioned_fields ( span, unmentioned_fields, variant) ;
904878 }
905879 no_field_errors
906880 }
@@ -916,6 +890,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
916890 . emit ( ) ;
917891 }
918892
893+ fn error_unmentioned_fields (
894+ & self ,
895+ span : Span ,
896+ unmentioned_fields : Vec < ast:: Ident > ,
897+ variant : & ty:: VariantDef ,
898+ ) {
899+ let field_names = if unmentioned_fields. len ( ) == 1 {
900+ format ! ( "field `{}`" , unmentioned_fields[ 0 ] )
901+ } else {
902+ let fields = unmentioned_fields. iter ( )
903+ . map ( |name| format ! ( "`{}`" , name) )
904+ . collect :: < Vec < String > > ( )
905+ . join ( ", " ) ;
906+ format ! ( "fields {}" , fields)
907+ } ;
908+ let mut diag = struct_span_err ! (
909+ self . tcx. sess, span, E0027 ,
910+ "pattern does not mention {}" ,
911+ field_names
912+ ) ;
913+ diag. span_label ( span, format ! ( "missing {}" , field_names) ) ;
914+ if variant. ctor_kind == CtorKind :: Fn {
915+ diag. note ( "trying to match a tuple variant with a struct variant pattern" ) ;
916+ }
917+ if self . tcx . sess . teach ( & diag. get_code ( ) . unwrap ( ) ) {
918+ diag. note (
919+ "This error indicates that a pattern for a struct fails to specify a \
920+ sub-pattern for every one of the struct's fields. Ensure that each field \
921+ from the struct's definition is mentioned in the pattern, or use `..` to \
922+ ignore unwanted fields."
923+ ) ;
924+ }
925+ diag. emit ( ) ;
926+ }
927+
919928 fn check_pat_box (
920929 & self ,
921930 span : Span ,
0 commit comments