@@ -1250,15 +1250,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1250
1250
tcx. sess . struct_span_err ( pat. span , "`..` cannot be used in union patterns" ) . emit ( ) ;
1251
1251
}
1252
1252
} else if !etc && !unmentioned_fields. is_empty ( ) {
1253
- let no_accessible_unmentioned_fields = !unmentioned_fields. iter ( ) . any ( |( field, _) | {
1254
- field. vis . is_accessible_from ( tcx. parent_module ( pat. hir_id ) . to_def_id ( ) , tcx)
1255
- } ) ;
1253
+ let accessible_unmentioned_fields: Vec < _ > = unmentioned_fields
1254
+ . iter ( )
1255
+ . copied ( )
1256
+ . filter ( |( field, _) | {
1257
+ field. vis . is_accessible_from ( tcx. parent_module ( pat. hir_id ) . to_def_id ( ) , tcx)
1258
+ } )
1259
+ . collect ( ) ;
1256
1260
1257
- if no_accessible_unmentioned_fields {
1261
+ if accessible_unmentioned_fields . is_empty ( ) {
1258
1262
unmentioned_err = Some ( self . error_no_accessible_fields ( pat, & fields) ) ;
1259
1263
} else {
1260
- unmentioned_err =
1261
- Some ( self . error_unmentioned_fields ( pat, & unmentioned_fields, & fields) ) ;
1264
+ unmentioned_err = Some ( self . error_unmentioned_fields (
1265
+ pat,
1266
+ & accessible_unmentioned_fields,
1267
+ accessible_unmentioned_fields. len ( ) != unmentioned_fields. len ( ) ,
1268
+ & fields,
1269
+ ) ) ;
1262
1270
}
1263
1271
}
1264
1272
match ( inexistent_fields_err, unmentioned_err) {
@@ -1583,17 +1591,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1583
1591
& self ,
1584
1592
pat : & Pat < ' _ > ,
1585
1593
unmentioned_fields : & [ ( & ty:: FieldDef , Ident ) ] ,
1594
+ have_inaccessible_fields : bool ,
1586
1595
fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
1587
1596
) -> DiagnosticBuilder < ' tcx > {
1597
+ let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" } ;
1588
1598
let field_names = if unmentioned_fields. len ( ) == 1 {
1589
- format ! ( "field `{}`" , unmentioned_fields[ 0 ] . 1 )
1599
+ format ! ( "field `{}`{} " , unmentioned_fields[ 0 ] . 1 , inaccessible )
1590
1600
} else {
1591
1601
let fields = unmentioned_fields
1592
1602
. iter ( )
1593
1603
. map ( |( _, name) | format ! ( "`{}`" , name) )
1594
1604
. collect :: < Vec < String > > ( )
1595
1605
. join ( ", " ) ;
1596
- format ! ( "fields {}" , fields)
1606
+ format ! ( "fields {}{} " , fields, inaccessible )
1597
1607
} ;
1598
1608
let mut err = struct_span_err ! (
1599
1609
self . tcx. sess,
@@ -1624,17 +1634,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1624
1634
err. span_suggestion (
1625
1635
sp,
1626
1636
& format ! (
1627
- "include the missing field{} in the pattern" ,
1637
+ "include the missing field{} in the pattern{} " ,
1628
1638
if len == 1 { "" } else { "s" } ,
1639
+ if have_inaccessible_fields { " and ignore the inaccessible fields" } else { "" }
1629
1640
) ,
1630
1641
format ! (
1631
- "{}{}{}" ,
1642
+ "{}{}{}{} " ,
1632
1643
prefix,
1633
1644
unmentioned_fields
1634
1645
. iter( )
1635
1646
. map( |( _, name) | name. to_string( ) )
1636
1647
. collect:: <Vec <_>>( )
1637
1648
. join( ", " ) ,
1649
+ if have_inaccessible_fields { ", .." } else { "" } ,
1638
1650
postfix,
1639
1651
) ,
1640
1652
Applicability :: MachineApplicable ,
0 commit comments