@@ -6,6 +6,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
66use rustc_hir:: lang_items:: LangItem ;
77use rustc_hir:: { Block , Expr , ExprKind , HirId , Local , Node , PatKind , PathSegment , StmtKind } ;
88use rustc_lint:: { LateContext , LateLintPass } ;
9+ use rustc_middle:: hir:: nested_filter:: OnlyBodies ;
910use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1011use rustc_span:: sym;
1112
@@ -109,8 +110,14 @@ impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
109110 }
110111}
111112
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 > ) {
114121 if self . found_peek_call {
115122 return ;
116123 }
@@ -136,12 +143,11 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
136143 return ;
137144 }
138145
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) ) {
142147 self . found_peek_call = true ;
143- return ;
144148 }
149+
150+ return ;
145151 } ,
146152 // Catch anything taking a Peekable mutably
147153 ExprKind :: MethodCall (
@@ -190,21 +196,21 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
190196 Node :: Local ( Local { init : Some ( init) , .. } ) => {
191197 if arg_is_mut_peekable ( self . cx , init) {
192198 self . found_peek_call = true ;
193- return ;
194199 }
195200
196- break ;
201+ return ;
197202 } ,
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 ;
204210 } ,
205211 Node :: Block ( _) | Node :: ExprField ( _) => { } ,
206212 _ => {
207- break ;
213+ return ;
208214 } ,
209215 }
210216 }
0 commit comments