@@ -883,23 +883,29 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
883883 }
884884
885885 if let ExprKind :: MethodCall ( path, recv, args, _) = expr. kind {
886- if matches ! (
887- path. ident. name,
888- sym:: all | sym:: any | sym:: filter_map | sym:: find_map | sym:: flat_map | sym:: for_each | sym:: map
889- ) && let [ arg] = args
890- {
891- unused_enumerate_index:: check_method ( cx, expr, recv, arg) ;
892- }
893-
894- if matches ! (
895- path. ident. name,
896- sym:: all | sym:: any | sym:: for_each | sym:: try_for_each | sym:: fold | sym:: try_fold | sym:: reduce
897- ) && cx
886+ let name = path. ident . name ;
887+ let is_iterator_method = cx
898888 . ty_based_def ( expr)
899889 . assoc_fn_parent ( cx)
900- . is_diag_item ( cx, sym:: Iterator )
901- {
902- never_loop:: check_iterator_reduction ( cx, expr, recv, args) ;
890+ . is_diag_item ( cx, sym:: Iterator ) ;
891+
892+ match ( name, args) {
893+ ( sym:: for_each | sym:: all | sym:: any, [ arg] ) => {
894+ unused_enumerate_index:: check_method ( cx, expr, recv, arg) ;
895+ if is_iterator_method {
896+ never_loop:: check_iterator_reduction ( cx, expr, recv, args) ;
897+ }
898+ } ,
899+
900+ ( sym:: filter_map | sym:: find_map | sym:: flat_map | sym:: map, [ arg] ) => {
901+ unused_enumerate_index:: check_method ( cx, expr, recv, arg) ;
902+ } ,
903+
904+ ( sym:: try_for_each | sym:: reduce | sym:: fold | sym:: try_fold, args) if is_iterator_method => {
905+ never_loop:: check_iterator_reduction ( cx, expr, recv, args) ;
906+ } ,
907+
908+ _ => { } ,
903909 }
904910 }
905911 }
0 commit comments