11use clippy_utils:: diagnostics:: span_lint_and_note;
22use clippy_utils:: source:: snippet;
33use clippy_utils:: visitors:: is_local_used;
4- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4+ use rustc_data_structures:: fx:: FxHashMap ;
55use rustc_hir:: def:: Res ;
66use rustc_hir:: def_id:: LocalDefId ;
77use 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 } ;
109use rustc_lint:: { LateContext , LateLintPass } ;
1110use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
1211use rustc_span:: { Span , Symbol } ;
@@ -96,7 +95,6 @@ declare_clippy_lint! {
9695#[ derive( Default ) ]
9796pub ( crate ) struct Shadow {
9897 bindings : Vec < FxHashMap < Symbol , Vec < ItemLocalId > > > ,
99- skip : Vec < FxHashSet < Symbol > > ,
10098}
10199
102100impl_lint_pass ! ( Shadow => [ SHADOW_SAME , SHADOW_REUSE , SHADOW_UNRELATED ] ) ;
@@ -107,11 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
107105 PatKind :: Binding ( _, hir_id, ident, _) => ( hir_id, ident) ,
108106 _ => return ,
109107 } ;
108+
109+ if pat. span . desugaring_kind ( ) . is_some ( ) {
110+ return ;
111+ }
112+
110113 if ident. span . from_expansion ( ) || ident. span . is_dummy ( ) {
111114 return ;
112115 }
113- let HirId { owner, local_id } = id;
114116
117+ let HirId { owner, local_id } = id;
115118 // get (or insert) the list of items for this owner and symbol
116119 let data = self . bindings . last_mut ( ) . unwrap ( ) ;
117120 let items_with_name = data. entry ( ident. name ) . or_default ( ) ;
@@ -123,11 +126,6 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
123126 return ;
124127 }
125128
126- if !self . skip . is_empty ( ) && self . skip . last_mut ( ) . unwrap ( ) . contains ( & ident. name ) {
127- // skip async function's params
128- return ;
129- }
130-
131129 if is_shadow ( cx, owner, prev, local_id) {
132130 let prev_hir_id = HirId { owner, local_id : prev } ;
133131 lint_shadow ( cx, pat, prev_hir_id, ident. span ) ;
@@ -152,58 +150,6 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
152150 self . bindings . pop ( ) ;
153151 }
154152 }
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- }
207153}
208154
209155fn is_shadow ( cx : & LateContext < ' _ > , owner : LocalDefId , first : ItemLocalId , second : ItemLocalId ) -> bool {
0 commit comments