@@ -11,7 +11,6 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintCon
11
11
use rustc_middle:: hir:: map:: Map ;
12
12
use rustc_middle:: lint:: in_external_macro;
13
13
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
14
- use rustc_span:: symbol:: Ident ;
15
14
16
15
declare_clippy_lint ! {
17
16
/// **What it does:** Detects closures called in the same expression where they
@@ -96,9 +95,9 @@ impl EarlyLintPass for RedundantClosureCall {
96
95
97
96
impl < ' tcx > LateLintPass < ' tcx > for RedundantClosureCall {
98
97
fn check_block ( & mut self , cx : & LateContext < ' tcx > , block : & ' tcx hir:: Block < ' _ > ) {
99
- fn count_closure_usage < ' tcx > ( block : & ' tcx hir:: Block < ' _ > , ident : & ' tcx Ident ) -> usize {
98
+ fn count_closure_usage < ' tcx > ( block : & ' tcx hir:: Block < ' _ > , path : & ' tcx hir :: Path < ' tcx > ) -> usize {
100
99
struct ClosureUsageCount < ' tcx > {
101
- ident : & ' tcx Ident ,
100
+ path : & ' tcx hir :: Path < ' tcx > ,
102
101
count : usize ,
103
102
} ;
104
103
impl < ' tcx > hir_visit:: Visitor < ' tcx > for ClosureUsageCount < ' tcx > {
@@ -108,7 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
108
107
if_chain ! {
109
108
if let hir:: ExprKind :: Call ( ref closure, _) = expr. kind;
110
109
if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = closure. kind;
111
- if self . ident == & path. segments[ 0 ] . ident;
110
+ if self . path. segments[ 0 ] . ident == path. segments[ 0 ] . ident
111
+ && self . path. res == path. res;
112
112
then {
113
113
self . count += 1 ;
114
114
}
@@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
120
120
hir_visit:: NestedVisitorMap :: None
121
121
}
122
122
} ;
123
- let mut closure_usage_count = ClosureUsageCount { ident , count : 0 } ;
123
+ let mut closure_usage_count = ClosureUsageCount { path , count : 0 } ;
124
124
closure_usage_count. visit_block ( block) ;
125
125
closure_usage_count. count
126
126
}
@@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
136
136
if let hir:: ExprKind :: Call ( ref closure, _) = call. kind;
137
137
if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = closure. kind;
138
138
if ident == path. segments[ 0 ] . ident;
139
- if count_closure_usage( block, & ident ) == 1 ;
139
+ if count_closure_usage( block, path ) == 1 ;
140
140
then {
141
141
span_lint(
142
142
cx,
0 commit comments