11use crate :: utils:: { match_def_path, paths, qpath_res, snippet, span_lint_and_note} ;
22use if_chain:: if_chain;
33use rustc_hir:: def:: Res ;
4+ use rustc_data_structures:: fx:: FxHashMap ;
45use rustc_hir:: { Block , Expr , ExprKind , PatKind , QPath , Stmt , StmtKind } ;
56use rustc_span:: symbol:: { Ident , Symbol } ;
67
@@ -56,7 +57,7 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
5657 // find all "later statement"'s where the fields of the binding set as
5758 // Default::default() get reassigned
5859 let mut first_assign = None ;
59- let mut assigned_fields = vec ! [ ] ;
60+ let mut assigned_fields = FxHashMap :: default ( ) ;
6061 for consequtive_statement in & block. stmts [ stmt_idx + 1 ..] {
6162 // interrupt if the statement is a let binding (`Local`) that shadows the original
6263 // binding
@@ -70,7 +71,9 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
7071 if let Some ( ( field_ident, assign_rhs) ) = field_reassigned_by_stmt ( consequtive_statement, & binding_name) {
7172 // extract and store the assigned value for help message
7273 let value_snippet = snippet ( cx, assign_rhs. span , ".." ) ;
73- assigned_fields. push ( ( field_ident. name , value_snippet) ) ;
74+ if !assigned_fields. contains_key ( & field_ident. name ) {
75+ assigned_fields. insert ( field_ident. name , value_snippet) ;
76+ }
7477
7578 // also set first instance of error for help message
7679 if first_assign. is_none ( ) {
0 commit comments