@@ -36,6 +36,10 @@ pointers. If you encounter this error you should try to avoid dereferencing the
3636You can read more about trait objects in the Trait Objects section of the Reference: \
3737 https://doc.rust-lang.org/reference/types.html#trait-objects";
3838
39+ fn is_number ( text : & str ) -> bool {
40+ text. chars ( ) . all ( |c : char | c. is_digit ( 10 ) )
41+ }
42+
3943/// Information about the expected type at the top level of type checking a pattern.
4044///
4145/// **NOTE:** This is only for use by diagnostics. Do NOT use for type checking logic!
@@ -1671,7 +1675,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16711675 fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
16721676 variant : & ty:: VariantDef ,
16731677 ) -> Option < DiagnosticBuilder < ' tcx , ErrorGuaranteed > > {
1674- if let ( Some ( CtorKind :: Fn ) , PatKind :: Struct ( qpath, ..) ) = ( variant. ctor_kind ( ) , & pat. kind ) {
1678+ if let ( Some ( CtorKind :: Fn ) , PatKind :: Struct ( qpath, pattern_fields, ..) ) =
1679+ ( variant. ctor_kind ( ) , & pat. kind )
1680+ {
1681+ let is_tuple_struct_match = !pattern_fields. is_empty ( )
1682+ && pattern_fields. iter ( ) . map ( |field| field. ident . name . as_str ( ) ) . all ( is_number) ;
1683+ if is_tuple_struct_match {
1684+ return None ;
1685+ }
1686+
16751687 let path = rustc_hir_pretty:: to_string ( rustc_hir_pretty:: NO_ANN , |s| {
16761688 s. print_qpath ( qpath, false )
16771689 } ) ;
@@ -1893,7 +1905,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18931905 prefix,
18941906 unmentioned_fields
18951907 . iter( )
1896- . map( |( _, name) | name. to_string( ) )
1908+ . map( |( _, name) | {
1909+ let field_name = name. to_string( ) ;
1910+ if is_number( & field_name) {
1911+ format!( "{}: _" , field_name)
1912+ } else {
1913+ field_name
1914+ }
1915+ } )
18971916 . collect:: <Vec <_>>( )
18981917 . join( ", " ) ,
18991918 if have_inaccessible_fields { ", .." } else { "" } ,
0 commit comments