]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/methods/excessive_for_each.rs
Trigger the lint iff exposure's body is ExprKind::Block.
[rust.git] / clippy_lints / src / methods / excessive_for_each.rs
index 36f92d5b95f9eab88479a1512846555d0c5931d5..f3e9e2400f16c3441cad36e1bb6c422061b21af7 100644 (file)
@@ -26,11 +26,11 @@ pub(super) fn lint(cx: &LateContext<'_>, expr: &'tcx Expr<'_>, args: &[&[Expr<'_
 
     if_chain! {
         if match_trait_method(cx, expr, &paths::ITERATOR);
-        if !match_trait_method(cx, for_each_receiver, &paths::ITERATOR);
         if is_target_ty(cx, cx.typeck_results().expr_ty(iter_receiver));
         if let ExprKind::Closure(_, _, body_id, ..) = for_each_arg.kind;
+        let body = cx.tcx.hir().body(body_id);
+        if let ExprKind::Block(..) = body.value.kind;
         then {
-            let body = cx.tcx.hir().body(body_id);
             let mut ret_span_collector = RetSpanCollector::new();
             ret_span_collector.visit_expr(&body.value);