@@ -26,7 +26,8 @@ mod while_let_on_iterator;
2626
2727use clippy_config:: Conf ;
2828use clippy_utils:: msrvs:: Msrv ;
29- use clippy_utils:: { higher, sym, ty} ;
29+ use clippy_utils:: res:: { MaybeDef , MaybeTypeckRes } ;
30+ use clippy_utils:: { higher, sym} ;
3031use rustc_ast:: Label ;
3132use rustc_hir:: { Expr , ExprKind , LoopSource , Pat } ;
3233use rustc_lint:: { LateContext , LateLintPass } ;
@@ -881,23 +882,25 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
881882 manual_while_let_some:: check ( cx, condition, body, span) ;
882883 }
883884
884- if let ExprKind :: MethodCall ( path, recv, [ arg ] , _) = expr. kind
885- && matches ! (
885+ if let ExprKind :: MethodCall ( path, recv, args , _) = expr. kind {
886+ if matches ! (
886887 path. ident. name,
887888 sym:: all | sym:: any | sym:: filter_map | sym:: find_map | sym:: flat_map | sym:: for_each | sym:: map
888- )
889- {
890- unused_enumerate_index:: check_method ( cx, expr, recv, arg) ;
891- }
889+ ) && let [ arg ] = args
890+ {
891+ unused_enumerate_index:: check_method ( cx, expr, recv, arg) ;
892+ }
892893
893- if let ExprKind :: MethodCall ( path, recv, args, _) = expr. kind
894- && matches ! (
894+ if matches ! (
895895 path. ident. name,
896- sym:: for_each | sym:: try_for_each | sym:: fold | sym:: try_fold | sym:: reduce | sym:: all | sym:: any
897- )
898- && ty:: get_iterator_item_ty ( cx, cx. typeck_results ( ) . expr_ty ( recv) ) . is_some ( )
899- {
900- never_loop:: check_iterator_reduction ( cx, expr, recv, args) ;
896+ sym:: all | sym:: any | sym:: for_each | sym:: try_for_each | sym:: fold | sym:: try_fold | sym:: reduce
897+ ) && cx
898+ . ty_based_def ( expr)
899+ . assoc_fn_parent ( cx)
900+ . is_diag_item ( cx, sym:: Iterator )
901+ {
902+ never_loop:: check_iterator_reduction ( cx, expr, recv, args) ;
903+ }
901904 }
902905 }
903906}
0 commit comments