@@ -8,6 +8,7 @@ use rustc_lint::{LateContext, LateLintPass};
8
8
use rustc_middle:: hir:: nested_filter:: OnlyBodies ;
9
9
use rustc_session:: declare_lint_pass;
10
10
use rustc_span:: sym;
11
+ use std:: ops:: ControlFlow ;
11
12
12
13
declare_clippy_lint ! {
13
14
/// ### What it does
@@ -113,16 +114,13 @@ impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
113
114
114
115
impl < ' tcx > Visitor < ' tcx > for PeekableVisitor < ' _ , ' tcx > {
115
116
type NestedFilter = OnlyBodies ;
117
+ type Result = ControlFlow < ( ) > ;
116
118
117
119
fn nested_visit_map ( & mut self ) -> Self :: Map {
118
120
self . cx . tcx . hir ( )
119
121
}
120
122
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 < ( ) > {
126
124
if path_to_local_id ( ex, self . expected_hir_id ) {
127
125
for ( _, node) in self . cx . tcx . hir ( ) . parent_iter ( ex. hir_id ) {
128
126
match node {
@@ -137,14 +135,15 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
137
135
&& func_did == into_iter_did
138
136
{
139
137
// Probably a for loop desugar, stop searching
140
- return ;
138
+ return ControlFlow :: Continue ( ( ) ) ;
141
139
}
142
140
143
141
if args. iter ( ) . any ( |arg| arg_is_mut_peekable ( self . cx , arg) ) {
144
142
self . found_peek_call = true ;
143
+ return ControlFlow :: Break ( ( ) ) ;
145
144
}
146
145
147
- return ;
146
+ return ControlFlow :: Continue ( ( ) ) ;
148
147
} ,
149
148
// Catch anything taking a Peekable mutably
150
149
ExprKind :: MethodCall (
@@ -163,57 +162,62 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
163
162
&& arg_is_mut_peekable ( self . cx , self_arg)
164
163
{
165
164
self . found_peek_call = true ;
166
- return ;
165
+ return ControlFlow :: Break ( ( ) ) ;
167
166
}
168
167
169
168
// foo.some_method() excluding Iterator methods
170
169
if remaining_args. iter ( ) . any ( |arg| arg_is_mut_peekable ( self . cx , arg) )
171
170
&& !is_trait_method ( self . cx , expr, sym:: Iterator )
172
171
{
173
172
self . found_peek_call = true ;
174
- return ;
173
+ return ControlFlow :: Break ( ( ) ) ;
175
174
}
176
175
177
176
// foo.by_ref(), keep checking for `peek`
178
177
if method_name == "by_ref" {
179
178
continue ;
180
179
}
181
180
182
- return ;
181
+ return ControlFlow :: Continue ( ( ) ) ;
183
182
} ,
184
183
ExprKind :: AddrOf ( _, Mutability :: Mut , _) | ExprKind :: Unary ( ..) | ExprKind :: DropTemps ( _) => {
185
184
} ,
186
- ExprKind :: AddrOf ( _, Mutability :: Not , _) => return ,
185
+ ExprKind :: AddrOf ( _, Mutability :: Not , _) => return ControlFlow :: Continue ( ( ) ) ,
187
186
_ => {
188
187
self . found_peek_call = true ;
189
- return ;
188
+ return ControlFlow :: Break ( ( ) ) ;
190
189
} ,
191
190
}
192
191
} ,
193
192
Node :: LetStmt ( LetStmt { init : Some ( init) , .. } ) => {
194
193
if arg_is_mut_peekable ( self . cx , init) {
195
194
self . found_peek_call = true ;
195
+ return ControlFlow :: Break ( ( ) ) ;
196
196
}
197
197
198
- return ;
198
+ return ControlFlow :: Continue ( ( ) ) ;
199
199
} ,
200
200
Node :: Stmt ( stmt) => {
201
201
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
+ } ,
203
206
StmtKind :: Expr ( _) | StmtKind :: Semi ( _) => { } ,
204
207
}
205
208
206
- return ;
209
+ return ControlFlow :: Continue ( ( ) ) ;
207
210
} ,
208
211
Node :: Block ( _) | Node :: ExprField ( _) => { } ,
209
212
_ => {
210
- return ;
213
+ return ControlFlow :: Continue ( ( ) ) ;
211
214
} ,
212
215
}
213
216
}
214
217
}
215
218
216
219
walk_expr ( self , ex) ;
220
+ ControlFlow :: Continue ( ( ) )
217
221
}
218
222
}
219
223
0 commit comments