1
- use crate :: ast;
2
1
use crate :: ast:: {
3
- BlockCheckMode , BinOpKind , Expr , ExprKind , Item , ItemKind , Pat , PatKind , PathSegment , QSelf ,
4
- Ty , TyKind , VariantData , Ident ,
2
+ self , Arg , BinOpKind , BindingMode , BlockCheckMode , Expr , ExprKind , Ident , Item , ItemKind ,
3
+ Mutability , Pat , PatKind , PathSegment , QSelf , Ty , TyKind , VariantData ,
5
4
} ;
6
5
use crate :: parse:: { SeqSep , token, PResult , Parser } ;
7
6
use crate :: parse:: parser:: { BlockMode , PathStyle , SemiColonMode , TokenType , TokenExpectType } ;
@@ -12,9 +11,25 @@ use crate::symbol::{kw, sym};
12
11
use crate :: ThinVec ;
13
12
use crate :: util:: parser:: AssocOp ;
14
13
use errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
14
+ use rustc_data_structures:: fx:: FxHashSet ;
15
15
use syntax_pos:: { Span , DUMMY_SP , MultiSpan } ;
16
16
use log:: { debug, trace} ;
17
17
18
+ /// Creates a placeholder argument.
19
+ crate fn dummy_arg ( ident : Ident ) -> Arg {
20
+ let pat = P ( Pat {
21
+ id : ast:: DUMMY_NODE_ID ,
22
+ node : PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , ident, None ) ,
23
+ span : ident. span ,
24
+ } ) ;
25
+ let ty = Ty {
26
+ node : TyKind :: Err ,
27
+ span : ident. span ,
28
+ id : ast:: DUMMY_NODE_ID
29
+ } ;
30
+ Arg { ty : P ( ty) , pat : pat, id : ast:: DUMMY_NODE_ID , source : ast:: ArgSource :: Normal }
31
+ }
32
+
18
33
pub enum Error {
19
34
FileNotFoundForModule {
20
35
mod_name : String ,
@@ -1217,4 +1232,24 @@ impl<'a> Parser<'a> {
1217
1232
err. span_label ( span, "expected expression" ) ;
1218
1233
err
1219
1234
}
1235
+
1236
+ /// Replace duplicated recovered arguments with `_` pattern to avoid unecessary errors.
1237
+ crate fn deduplicate_recovered_arg_names ( & self , fn_inputs : & mut Vec < Arg > ) {
1238
+ let mut seen_inputs = FxHashSet :: default ( ) ;
1239
+ for input in fn_inputs. iter_mut ( ) {
1240
+ let opt_ident = if let ( PatKind :: Ident ( _, ident, _) , TyKind :: Err ) = (
1241
+ & input. pat . node , & input. ty . node ,
1242
+ ) {
1243
+ Some ( * ident)
1244
+ } else {
1245
+ None
1246
+ } ;
1247
+ if let Some ( ident) = opt_ident {
1248
+ if seen_inputs. contains ( & ident) {
1249
+ input. pat . node = PatKind :: Wild ;
1250
+ }
1251
+ seen_inputs. insert ( ident) ;
1252
+ }
1253
+ }
1254
+ }
1220
1255
}
0 commit comments