@@ -6,6 +6,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
6
6
use rustc_hir:: lang_items:: LangItem ;
7
7
use rustc_hir:: { Block , Expr , ExprKind , HirId , Local , Node , PatKind , PathSegment , StmtKind } ;
8
8
use rustc_lint:: { LateContext , LateLintPass } ;
9
+ use rustc_middle:: hir:: nested_filter:: OnlyBodies ;
9
10
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
10
11
use rustc_span:: sym;
11
12
@@ -109,8 +110,14 @@ impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
109
110
}
110
111
}
111
112
112
- impl < ' tcx > Visitor < ' _ > for PeekableVisitor < ' _ , ' tcx > {
113
- fn visit_expr ( & mut self , ex : & ' _ Expr < ' _ > ) {
113
+ impl < ' tcx > Visitor < ' tcx > for PeekableVisitor < ' _ , ' tcx > {
114
+ type NestedFilter = OnlyBodies ;
115
+
116
+ fn nested_visit_map ( & mut self ) -> Self :: Map {
117
+ self . cx . tcx . hir ( )
118
+ }
119
+
120
+ fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
114
121
if self . found_peek_call {
115
122
return ;
116
123
}
@@ -136,12 +143,11 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
136
143
return ;
137
144
}
138
145
139
- if args. iter ( ) . any ( |arg| {
140
- matches ! ( arg. kind, ExprKind :: Path ( _) ) && arg_is_mut_peekable ( self . cx , arg)
141
- } ) {
146
+ if args. iter ( ) . any ( |arg| arg_is_mut_peekable ( self . cx , arg) ) {
142
147
self . found_peek_call = true ;
143
- return ;
144
148
}
149
+
150
+ return ;
145
151
} ,
146
152
// Catch anything taking a Peekable mutably
147
153
ExprKind :: MethodCall (
@@ -190,21 +196,21 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
190
196
Node :: Local ( Local { init : Some ( init) , .. } ) => {
191
197
if arg_is_mut_peekable ( self . cx , init) {
192
198
self . found_peek_call = true ;
193
- return ;
194
199
}
195
200
196
- break ;
201
+ return ;
197
202
} ,
198
- Node :: Stmt ( stmt) => match stmt. kind {
199
- StmtKind :: Expr ( _) | StmtKind :: Semi ( _) => { } ,
200
- _ => {
201
- self . found_peek_call = true ;
202
- return ;
203
- } ,
203
+ Node :: Stmt ( stmt) => {
204
+ match stmt. kind {
205
+ StmtKind :: Local ( _) | StmtKind :: Item ( _) => self . found_peek_call = true ,
206
+ StmtKind :: Expr ( _) | StmtKind :: Semi ( _) => { } ,
207
+ }
208
+
209
+ return ;
204
210
} ,
205
211
Node :: Block ( _) | Node :: ExprField ( _) => { } ,
206
212
_ => {
207
- break ;
213
+ return ;
208
214
} ,
209
215
}
210
216
}
0 commit comments