Skip to content

Commit 19dd6d8

Browse files
committed
Add comments to clarify why RetCollector is needed
1 parent 74b85a4 commit 19dd6d8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

clippy_lints/src/methods/excessive_for_each.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ pub(super) fn lint(cx: &LateContext<'_>, expr: &'tcx Expr<'_>, args: &[&[Expr<'_
6666
/// This type plays two roles.
6767
/// 1. Collect spans of `return` in the closure body.
6868
/// 2. Detect use of `return` in `Loop` in the closure body.
69+
///
70+
/// NOTE: The functionality of this type is similar to
71+
/// [`crate::utilts::visitors::find_all_ret_expressions`], but we can't use
72+
/// `find_all_ret_expressions` instead of this type. The reasons are:
73+
/// 1. `find_all_ret_expressions` passes the argument of `ExprKind::Ret` to a callback, but what we
74+
/// need here is `ExprKind::Ret` itself.
75+
/// 2. We can't trace current loop depth with `find_all_ret_expressions`.
6976
struct RetCollector {
7077
spans: Vec<Span>,
7178
ret_in_loop: bool,

0 commit comments

Comments
 (0)