1
1
use crate :: utils:: { match_def_path, paths, qpath_res, snippet, span_lint_and_note} ;
2
2
use if_chain:: if_chain;
3
3
use rustc_hir:: def:: Res ;
4
+ use rustc_data_structures:: fx:: FxHashMap ;
4
5
use rustc_hir:: { Block , Expr , ExprKind , PatKind , QPath , Stmt , StmtKind } ;
5
6
use rustc_span:: symbol:: { Ident , Symbol } ;
6
7
@@ -56,7 +57,7 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
56
57
// find all "later statement"'s where the fields of the binding set as
57
58
// Default::default() get reassigned
58
59
let mut first_assign = None ;
59
- let mut assigned_fields = vec ! [ ] ;
60
+ let mut assigned_fields = FxHashMap :: default ( ) ;
60
61
for consequtive_statement in & block. stmts [ stmt_idx + 1 ..] {
61
62
// interrupt if the statement is a let binding (`Local`) that shadows the original
62
63
// binding
@@ -70,7 +71,9 @@ impl LateLintPass<'_> for FieldReassignWithDefault {
70
71
if let Some ( ( field_ident, assign_rhs) ) = field_reassigned_by_stmt ( consequtive_statement, & binding_name) {
71
72
// extract and store the assigned value for help message
72
73
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
+ }
74
77
75
78
// also set first instance of error for help message
76
79
if first_assign. is_none ( ) {
0 commit comments