@@ -8,6 +8,7 @@ use rustc_lint::{LateContext, LateLintPass};
88use rustc_middle:: hir:: nested_filter:: OnlyBodies ;
99use rustc_session:: declare_lint_pass;
1010use rustc_span:: sym;
11+ use std:: ops:: ControlFlow ;
1112
1213declare_clippy_lint ! {
1314 /// ### What it does
@@ -113,16 +114,13 @@ impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
113114
114115impl < ' tcx > Visitor < ' tcx > for PeekableVisitor < ' _ , ' tcx > {
115116 type NestedFilter = OnlyBodies ;
117+ type Result = ControlFlow < ( ) > ;
116118
117119 fn nested_visit_map ( & mut self ) -> Self :: Map {
118120 self . cx . tcx . hir ( )
119121 }
120122
121- fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
122- if self . found_peek_call {
123- return ;
124- }
125-
123+ fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) -> ControlFlow < ( ) > {
126124 if path_to_local_id ( ex, self . expected_hir_id ) {
127125 for ( _, node) in self . cx . tcx . hir ( ) . parent_iter ( ex. hir_id ) {
128126 match node {
@@ -137,14 +135,15 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
137135 && func_did == into_iter_did
138136 {
139137 // Probably a for loop desugar, stop searching
140- return ;
138+ return ControlFlow :: Continue ( ( ) ) ;
141139 }
142140
143141 if args. iter ( ) . any ( |arg| arg_is_mut_peekable ( self . cx , arg) ) {
144142 self . found_peek_call = true ;
143+ return ControlFlow :: Break ( ( ) ) ;
145144 }
146145
147- return ;
146+ return ControlFlow :: Continue ( ( ) ) ;
148147 } ,
149148 // Catch anything taking a Peekable mutably
150149 ExprKind :: MethodCall (
@@ -163,57 +162,62 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
163162 && arg_is_mut_peekable ( self . cx , self_arg)
164163 {
165164 self . found_peek_call = true ;
166- return ;
165+ return ControlFlow :: Break ( ( ) ) ;
167166 }
168167
169168 // foo.some_method() excluding Iterator methods
170169 if remaining_args. iter ( ) . any ( |arg| arg_is_mut_peekable ( self . cx , arg) )
171170 && !is_trait_method ( self . cx , expr, sym:: Iterator )
172171 {
173172 self . found_peek_call = true ;
174- return ;
173+ return ControlFlow :: Break ( ( ) ) ;
175174 }
176175
177176 // foo.by_ref(), keep checking for `peek`
178177 if method_name == "by_ref" {
179178 continue ;
180179 }
181180
182- return ;
181+ return ControlFlow :: Continue ( ( ) ) ;
183182 } ,
184183 ExprKind :: AddrOf ( _, Mutability :: Mut , _) | ExprKind :: Unary ( ..) | ExprKind :: DropTemps ( _) => {
185184 } ,
186- ExprKind :: AddrOf ( _, Mutability :: Not , _) => return ,
185+ ExprKind :: AddrOf ( _, Mutability :: Not , _) => return ControlFlow :: Continue ( ( ) ) ,
187186 _ => {
188187 self . found_peek_call = true ;
189- return ;
188+ return ControlFlow :: Break ( ( ) ) ;
190189 } ,
191190 }
192191 } ,
193192 Node :: LetStmt ( LetStmt { init : Some ( init) , .. } ) => {
194193 if arg_is_mut_peekable ( self . cx , init) {
195194 self . found_peek_call = true ;
195+ return ControlFlow :: Break ( ( ) ) ;
196196 }
197197
198- return ;
198+ return ControlFlow :: Continue ( ( ) ) ;
199199 } ,
200200 Node :: Stmt ( stmt) => {
201201 match stmt. kind {
202- StmtKind :: Let ( _) | StmtKind :: Item ( _) => self . found_peek_call = true ,
202+ StmtKind :: Let ( _) | StmtKind :: Item ( _) => {
203+ self . found_peek_call = true ;
204+ return ControlFlow :: Break ( ( ) ) ;
205+ } ,
203206 StmtKind :: Expr ( _) | StmtKind :: Semi ( _) => { } ,
204207 }
205208
206- return ;
209+ return ControlFlow :: Continue ( ( ) ) ;
207210 } ,
208211 Node :: Block ( _) | Node :: ExprField ( _) => { } ,
209212 _ => {
210- return ;
213+ return ControlFlow :: Continue ( ( ) ) ;
211214 } ,
212215 }
213216 }
214217 }
215218
216219 walk_expr ( self , ex) ;
220+ ControlFlow :: Continue ( ( ) )
217221 }
218222}
219223
0 commit comments