@@ -99,7 +99,7 @@ declare_clippy_lint! {
99
99
100
100
#[ derive( Default ) ]
101
101
pub ( crate ) struct Shadow {
102
- bindings : Vec < FxHashMap < Symbol , Vec < ItemLocalId > > > ,
102
+ bindings : Vec < ( FxHashMap < Symbol , Vec < ItemLocalId > > , LocalDefId ) > ,
103
103
}
104
104
105
105
impl_lint_pass ! ( Shadow => [ SHADOW_SAME , SHADOW_REUSE , SHADOW_UNRELATED ] ) ;
@@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
121
121
122
122
let HirId { owner, local_id } = id;
123
123
// get (or insert) the list of items for this owner and symbol
124
- let data = self . bindings . last_mut ( ) . unwrap ( ) ;
124
+ let ( ref mut data, scope_owner ) = * self . bindings . last_mut ( ) . unwrap ( ) ;
125
125
let items_with_name = data. entry ( ident. name ) . or_default ( ) ;
126
126
127
127
// check other bindings with the same name, most recently seen first
@@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
131
131
return ;
132
132
}
133
133
134
- if is_shadow ( cx, owner , prev, local_id) {
134
+ if is_shadow ( cx, scope_owner , prev, local_id) {
135
135
let prev_hir_id = HirId { owner, local_id : prev } ;
136
136
lint_shadow ( cx, pat, prev_hir_id, ident. span ) ;
137
137
// only lint against the "nearest" shadowed binding
@@ -144,11 +144,9 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
144
144
145
145
fn check_body ( & mut self , cx : & LateContext < ' _ > , body : & Body < ' _ > ) {
146
146
let hir = cx. tcx . hir ( ) ;
147
- if !matches ! (
148
- hir. body_owner_kind( hir. body_owner_def_id( body. id( ) ) ) ,
149
- BodyOwnerKind :: Closure
150
- ) {
151
- self . bindings . push ( FxHashMap :: default ( ) ) ;
147
+ let owner_id = hir. body_owner_def_id ( body. id ( ) ) ;
148
+ if !matches ! ( hir. body_owner_kind( owner_id) , BodyOwnerKind :: Closure ) {
149
+ self . bindings . push ( ( FxHashMap :: default ( ) , owner_id) ) ;
152
150
}
153
151
}
154
152
0 commit comments