1- use crate :: ast;
21use 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 ,
54} ;
65use crate :: parse:: { SeqSep , token, PResult , Parser } ;
76use crate :: parse:: parser:: { BlockMode , PathStyle , SemiColonMode , TokenType , TokenExpectType } ;
@@ -12,9 +11,25 @@ use crate::symbol::{kw, sym};
1211use crate :: ThinVec ;
1312use crate :: util:: parser:: AssocOp ;
1413use errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
14+ use rustc_data_structures:: fx:: FxHashSet ;
1515use syntax_pos:: { Span , DUMMY_SP , MultiSpan } ;
1616use log:: { debug, trace} ;
1717
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+
1833pub enum Error {
1934 FileNotFoundForModule {
2035 mod_name : String ,
@@ -1217,4 +1232,24 @@ impl<'a> Parser<'a> {
12171232 err. span_label ( span, "expected expression" ) ;
12181233 err
12191234 }
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+ }
12201255}
0 commit comments