@@ -1013,12 +1013,15 @@ impl<'a> Parser<'a> {
1013
1013
}
1014
1014
ate_comma = false ;
1015
1015
1016
- if self . check ( & token:: DotDot ) || self . token == token:: DotDotDot {
1016
+ if self . check ( & token:: DotDot )
1017
+ || self . check_noexpect ( & token:: DotDotDot )
1018
+ || self . check_keyword ( kw:: Underscore )
1019
+ {
1017
1020
etc = true ;
1018
1021
let mut etc_sp = self . token . span ;
1019
1022
1020
- self . recover_one_fewer_dotdot ( ) ;
1021
- self . bump ( ) ; // `..` || `...`
1023
+ self . recover_bad_dot_dot ( ) ;
1024
+ self . bump ( ) ; // `..` || `...` || `_`
1022
1025
1023
1026
if self . token == token:: CloseDelim ( Delimiter :: Brace ) {
1024
1027
etc_span = Some ( etc_sp) ;
@@ -1111,21 +1114,25 @@ impl<'a> Parser<'a> {
1111
1114
Ok ( ( fields, etc) )
1112
1115
}
1113
1116
1114
- /// Recover on `...` as if it were `..` to avoid further errors.
1117
+ /// Recover on `...` or `_` as if it were `..` to avoid further errors.
1115
1118
/// See issue #46718.
1116
- fn recover_one_fewer_dotdot ( & self ) {
1117
- if self . token != token:: DotDotDot {
1119
+ fn recover_bad_dot_dot ( & self ) {
1120
+ if self . token == token:: DotDot {
1118
1121
return ;
1119
1122
}
1120
1123
1121
- self . struct_span_err ( self . token . span , "expected field pattern, found `...`" )
1122
- . span_suggestion (
1123
- self . token . span ,
1124
- "to omit remaining fields, use one fewer `.`" ,
1125
- ".." ,
1126
- Applicability :: MachineApplicable ,
1127
- )
1128
- . emit ( ) ;
1124
+ let token_str = pprust:: token_to_string ( & self . token ) ;
1125
+ self . struct_span_err (
1126
+ self . token . span ,
1127
+ format ! ( "expected field pattern, found `{token_str}`" ) ,
1128
+ )
1129
+ . span_suggestion_verbose (
1130
+ self . token . span ,
1131
+ "to omit remaining fields, use `..`" ,
1132
+ ".." ,
1133
+ Applicability :: MachineApplicable ,
1134
+ )
1135
+ . emit ( ) ;
1129
1136
}
1130
1137
1131
1138
fn parse_pat_field ( & mut self , lo : Span , attrs : AttrVec ) -> PResult < ' a , PatField > {
0 commit comments