@@ -36,6 +36,10 @@ pointers. If you encounter this error you should try to avoid dereferencing the
36
36
You can read more about trait objects in the Trait Objects section of the Reference: \
37
37
https://doc.rust-lang.org/reference/types.html#trait-objects";
38
38
39
+ fn is_number ( text : & str ) -> bool {
40
+ text. chars ( ) . all ( |c : char | c. is_digit ( 10 ) )
41
+ }
42
+
39
43
/// Information about the expected type at the top level of type checking a pattern.
40
44
///
41
45
/// **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> {
1671
1675
fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
1672
1676
variant : & ty:: VariantDef ,
1673
1677
) -> 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
+
1675
1687
let path = rustc_hir_pretty:: to_string ( rustc_hir_pretty:: NO_ANN , |s| {
1676
1688
s. print_qpath ( qpath, false )
1677
1689
} ) ;
@@ -1893,7 +1905,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1893
1905
prefix,
1894
1906
unmentioned_fields
1895
1907
. 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
+ } )
1897
1916
. collect:: <Vec <_>>( )
1898
1917
. join( ", " ) ,
1899
1918
if have_inaccessible_fields { ", .." } else { "" } ,
0 commit comments