@@ -5,10 +5,9 @@ use crate::utils::sugg::Sugg;
55use crate :: utils:: usage:: { is_unused, mutated_variables} ;
66use crate :: utils:: {
77 get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait,
8- is_integer_const, is_no_std_crate, is_refutable, is_type_diagnostic_item, last_path_segment, match_path,
9- match_trait_method, match_type, match_var, multispan_sugg, qpath_res, snippet, snippet_opt,
10- snippet_with_applicability, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg,
11- SpanlessEq ,
8+ is_integer_const, is_no_std_crate, is_refutable, is_type_diagnostic_item, last_path_segment, match_trait_method,
9+ match_type, match_var, multispan_sugg, qpath_res, snippet, snippet_opt, snippet_with_applicability, span_lint,
10+ span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg, SpanlessEq ,
1211} ;
1312use if_chain:: if_chain;
1413use rustc_ast:: ast;
@@ -2514,16 +2513,16 @@ enum IterFunctionKind {
25142513struct IterFunctionVisitor {
25152514 uses : Vec < IterFunction > ,
25162515 seen_other : bool ,
2517- target : String ,
2516+ target : Ident ,
25182517}
25192518impl < ' tcx > Visitor < ' tcx > for IterFunctionVisitor {
25202519 fn visit_expr ( & mut self , expr : & ' tcx Expr < ' tcx > ) {
2521- // TODO Check if the target identifier is being used in something other
2522- // than a function call
2520+ // Check function calls on our collection
25232521 if_chain ! {
25242522 if let ExprKind :: MethodCall ( method_name, _, ref args, _) = & expr. kind;
25252523 if let Some ( Expr { kind: ExprKind :: Path ( QPath :: Resolved ( _, ref path) ) , .. } ) = args. get( 0 ) ;
2526- if match_path( path, & [ & self . target] ) ;
2524+ if let & [ name] = & path. segments;
2525+ if name. ident == self . target;
25272526 then {
25282527 let into_iter = sym!( into_iter) ;
25292528 let len = sym!( len) ;
@@ -2544,8 +2543,17 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
25442543 ) ,
25452544 _ => self . seen_other = true ,
25462545 }
2546+ return
25472547 }
2548- else {
2548+ }
2549+ // Check if the collection is used for anything else
2550+ if_chain ! {
2551+ if let Expr { kind: ExprKind :: Path ( QPath :: Resolved ( _, ref path) ) , .. } = expr;
2552+ if let & [ name] = & path. segments;
2553+ if name. ident == self . target;
2554+ then {
2555+ self . seen_other = true ;
2556+ } else {
25492557 walk_expr( self , expr) ;
25502558 }
25512559 }
@@ -2562,7 +2570,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
25622570fn detect_iter_and_into_iters < ' tcx > ( block : & ' tcx Block < ' tcx > , identifier : Ident ) -> Option < Vec < IterFunction > > {
25632571 let mut visitor = IterFunctionVisitor {
25642572 uses : Vec :: new ( ) ,
2565- target : identifier. name . to_ident_string ( ) ,
2573+ target : identifier,
25662574 seen_other : false ,
25672575 } ;
25682576 visitor. visit_block ( block) ;
0 commit comments