@@ -8,7 +8,7 @@ use core::fmt::{self, Write};
8
8
use rustc_errors:: Applicability ;
9
9
use rustc_hir:: hir_id:: HirIdSet ;
10
10
use rustc_hir:: intravisit:: { Visitor , walk_expr} ;
11
- use rustc_hir:: { Block , Expr , ExprKind , HirId , Pat , Stmt , StmtKind , UnOp } ;
11
+ use rustc_hir:: { Block , Expr , ExprKind , HirId , Pat , QPath , Stmt , StmtKind , UnOp } ;
12
12
use rustc_lint:: { LateContext , LateLintPass } ;
13
13
use rustc_session:: declare_lint_pass;
14
14
use rustc_span:: { DUMMY_SP , Span , SyntaxContext , sym} ;
@@ -500,7 +500,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
500
500
self . visit_non_tail_expr ( insert_expr. value ) ;
501
501
self . is_single_insert = is_single_insert;
502
502
} ,
503
- _ if SpanlessEq :: new ( self . cx ) . eq_expr ( self . map , expr) => {
503
+ _ if is_map_used ( self . cx , self . map , expr) => {
504
504
self . is_map_used = true ;
505
505
} ,
506
506
_ => match expr. kind {
@@ -562,6 +562,22 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
562
562
}
563
563
}
564
564
565
+ fn is_map_used ( cx : & LateContext < ' _ > , map : & Expr < ' _ > , expr : & Expr < ' _ > ) -> bool {
566
+ if SpanlessEq :: new ( cx) . eq_expr ( map, expr) {
567
+ return true ;
568
+ }
569
+
570
+ match map. kind {
571
+ ExprKind :: Field ( inner, _) | ExprKind :: Index ( inner, _, _) => is_map_used ( cx, inner, expr) ,
572
+ ExprKind :: Path ( QPath :: Resolved ( _, map_path) )
573
+ if let ExprKind :: Path ( QPath :: Resolved ( _, expr_path) ) = expr. kind =>
574
+ {
575
+ SpanlessEq :: new ( cx) . eq_path ( map_path, expr_path)
576
+ } ,
577
+ _ => false ,
578
+ }
579
+ }
580
+
565
581
struct InsertSearchResults < ' tcx > {
566
582
edits : Vec < Edit < ' tcx > > ,
567
583
allow_insert_closure : bool ,
0 commit comments