1
1
use clippy_utils:: diagnostics:: span_lint_and_note;
2
2
use clippy_utils:: source:: snippet;
3
3
use clippy_utils:: visitors:: is_local_used;
4
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4
+ use rustc_data_structures:: fx:: FxHashMap ;
5
5
use rustc_hir:: def:: Res ;
6
6
use rustc_hir:: def_id:: LocalDefId ;
7
7
use rustc_hir:: hir_id:: ItemLocalId ;
8
- use rustc_hir:: intravisit:: FnKind ;
9
- use rustc_hir:: { Block , Body , BodyOwnerKind , Expr , ExprKind , FnDecl , HirId , IsAsync , Node , Pat , PatKind , QPath , UnOp } ;
8
+ use rustc_hir:: { Block , Body , BodyOwnerKind , Expr , ExprKind , HirId , Node , Pat , PatKind , QPath , UnOp } ;
10
9
use rustc_lint:: { LateContext , LateLintPass } ;
11
10
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
12
11
use rustc_span:: { Span , Symbol } ;
@@ -96,7 +95,6 @@ declare_clippy_lint! {
96
95
#[ derive( Default ) ]
97
96
pub ( crate ) struct Shadow {
98
97
bindings : Vec < FxHashMap < Symbol , Vec < ItemLocalId > > > ,
99
- skip : Vec < FxHashSet < Symbol > > ,
100
98
}
101
99
102
100
impl_lint_pass ! ( Shadow => [ SHADOW_SAME , SHADOW_REUSE , SHADOW_UNRELATED ] ) ;
@@ -107,11 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
107
105
PatKind :: Binding ( _, hir_id, ident, _) => ( hir_id, ident) ,
108
106
_ => return ,
109
107
} ;
108
+
109
+ if pat. span . desugaring_kind ( ) . is_some ( ) {
110
+ return ;
111
+ }
112
+
110
113
if ident. span . from_expansion ( ) || ident. span . is_dummy ( ) {
111
114
return ;
112
115
}
113
- let HirId { owner, local_id } = id;
114
116
117
+ let HirId { owner, local_id } = id;
115
118
// get (or insert) the list of items for this owner and symbol
116
119
let data = self . bindings . last_mut ( ) . unwrap ( ) ;
117
120
let items_with_name = data. entry ( ident. name ) . or_default ( ) ;
@@ -123,11 +126,6 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
123
126
return ;
124
127
}
125
128
126
- if !self . skip . is_empty ( ) && self . skip . last_mut ( ) . unwrap ( ) . contains ( & ident. name ) {
127
- // skip async function's params
128
- return ;
129
- }
130
-
131
129
if is_shadow ( cx, owner, prev, local_id) {
132
130
let prev_hir_id = HirId { owner, local_id : prev } ;
133
131
lint_shadow ( cx, pat, prev_hir_id, ident. span ) ;
@@ -152,58 +150,6 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
152
150
self . bindings . pop ( ) ;
153
151
}
154
152
}
155
-
156
- fn check_fn (
157
- & mut self ,
158
- _: & LateContext < ' tcx > ,
159
- kind : FnKind < ' tcx > ,
160
- _: & ' tcx FnDecl < ' _ > ,
161
- body : & ' tcx Body < ' _ > ,
162
- _: Span ,
163
- _: HirId ,
164
- ) {
165
- if_chain ! {
166
- if let Some ( header) = match kind {
167
- FnKind :: ItemFn ( _, _, header, _) => Some ( header) ,
168
- FnKind :: Method ( _, sig, _) => Some ( sig. header) ,
169
- FnKind :: Closure => None ,
170
- } ;
171
- if header. asyncness == IsAsync :: Async ;
172
- if !body. params. is_empty( ) ;
173
- then {
174
- self . skip. push( FxHashSet :: default ( ) ) ;
175
- let skip_params = self . skip. last_mut( ) . unwrap( ) ;
176
- for i in body. params {
177
- if let PatKind :: Binding ( .., ident, _) = i. pat. kind {
178
- skip_params. insert( ident. name) ;
179
- }
180
- }
181
- }
182
- }
183
- }
184
-
185
- fn check_fn_post (
186
- & mut self ,
187
- _: & LateContext < ' tcx > ,
188
- kind : FnKind < ' tcx > ,
189
- _: & ' tcx FnDecl < ' _ > ,
190
- body : & ' tcx Body < ' _ > ,
191
- _: Span ,
192
- _: HirId ,
193
- ) {
194
- if_chain ! {
195
- if let Some ( header) = match kind {
196
- FnKind :: ItemFn ( _, _, header, _) => Some ( header) ,
197
- FnKind :: Method ( _, sig, _) => Some ( sig. header) ,
198
- FnKind :: Closure => None ,
199
- } ;
200
- if header. asyncness == IsAsync :: Async ;
201
- if !body. params. is_empty( ) ;
202
- then {
203
- self . skip. pop( ) ;
204
- }
205
- }
206
- }
207
153
}
208
154
209
155
fn is_shadow ( cx : & LateContext < ' _ > , owner : LocalDefId , first : ItemLocalId , second : ItemLocalId ) -> bool {
0 commit comments