@@ -2,8 +2,8 @@ use clippy_utils::ty::{has_iter_method, implements_trait};
2
2
use clippy_utils:: { get_parent_expr, is_integer_const, path_to_local, path_to_local_id, sugg} ;
3
3
use rustc_ast:: ast:: { LitIntType , LitKind } ;
4
4
use rustc_errors:: Applicability ;
5
- use rustc_hir:: intravisit:: { walk_expr, walk_local, walk_pat , walk_stmt , Visitor } ;
6
- use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , HirId , HirIdMap , Local , Mutability , Pat , PatKind , Stmt } ;
5
+ use rustc_hir:: intravisit:: { walk_expr, walk_local, Visitor } ;
6
+ use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , HirId , HirIdMap , Local , Mutability , PatKind } ;
7
7
use rustc_lint:: LateContext ;
8
8
use rustc_middle:: hir:: nested_filter;
9
9
use rustc_middle:: ty:: { self , Ty } ;
@@ -253,62 +253,6 @@ fn is_conditional(expr: &Expr<'_>) -> bool {
253
253
matches ! ( expr. kind, ExprKind :: If ( ..) | ExprKind :: Match ( ..) )
254
254
}
255
255
256
- #[ derive( PartialEq , Eq ) ]
257
- pub ( super ) enum Nesting {
258
- Unknown , // no nesting detected yet
259
- RuledOut , // the iterator is initialized or assigned within scope
260
- LookFurther , // no nesting detected, no further walk required
261
- }
262
-
263
- use self :: Nesting :: { LookFurther , RuledOut , Unknown } ;
264
-
265
- pub ( super ) struct LoopNestVisitor {
266
- pub ( super ) hir_id : HirId ,
267
- pub ( super ) iterator : HirId ,
268
- pub ( super ) nesting : Nesting ,
269
- }
270
-
271
- impl < ' tcx > Visitor < ' tcx > for LoopNestVisitor {
272
- fn visit_stmt ( & mut self , stmt : & ' tcx Stmt < ' _ > ) {
273
- if stmt. hir_id == self . hir_id {
274
- self . nesting = LookFurther ;
275
- } else if self . nesting == Unknown {
276
- walk_stmt ( self , stmt) ;
277
- }
278
- }
279
-
280
- fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) {
281
- if self . nesting != Unknown {
282
- return ;
283
- }
284
- if expr. hir_id == self . hir_id {
285
- self . nesting = LookFurther ;
286
- return ;
287
- }
288
- match expr. kind {
289
- ExprKind :: Assign ( path, _, _) | ExprKind :: AssignOp ( _, path, _) => {
290
- if path_to_local_id ( path, self . iterator ) {
291
- self . nesting = RuledOut ;
292
- }
293
- } ,
294
- _ => walk_expr ( self , expr) ,
295
- }
296
- }
297
-
298
- fn visit_pat ( & mut self , pat : & ' tcx Pat < ' _ > ) {
299
- if self . nesting != Unknown {
300
- return ;
301
- }
302
- if let PatKind :: Binding ( _, id, ..) = pat. kind {
303
- if id == self . iterator {
304
- self . nesting = RuledOut ;
305
- return ;
306
- }
307
- }
308
- walk_pat ( self , pat) ;
309
- }
310
- }
311
-
312
256
/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the
313
257
/// actual `Iterator` that the loop uses.
314
258
pub ( super ) fn make_iterator_snippet ( cx : & LateContext < ' _ > , arg : & Expr < ' _ > , applic_ref : & mut Applicability ) -> String {
0 commit comments