about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-02-23 21:55:00 +0900
committerYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-04-01 00:05:42 +0900
commit25d8b94cecf5f7d17fc1d3d6140b62ae2f910b56 (patch)
tree39b75c82a8432cfb30c881a872c8648f19e43432
parentccd7a600233ead22a77e024503edf4ef679c1751 (diff)
downloadrust-25d8b94cecf5f7d17fc1d3d6140b62ae2f910b56.tar.gz
rust-25d8b94cecf5f7d17fc1d3d6140b62ae2f910b56.zip
Add comments to clarify why RetCollector is needed
-rw-r--r--clippy_lints/src/methods/excessive_for_each.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/clippy_lints/src/methods/excessive_for_each.rs b/clippy_lints/src/methods/excessive_for_each.rs
index 14aef0e99d5..470f4ea2204 100644
--- a/clippy_lints/src/methods/excessive_for_each.rs
+++ b/clippy_lints/src/methods/excessive_for_each.rs
@@ -66,6 +66,13 @@ pub(super) fn lint(cx: &LateContext<'_>, expr: &'tcx Expr<'_>, args: &[&[Expr<'_
 /// This type plays two roles.
 /// 1. Collect spans of `return` in the closure body.
 /// 2. Detect use of `return` in `Loop` in the closure body.
+///
+/// NOTE: The functionality of this type is similar to
+/// [`crate::utilts::visitors::find_all_ret_expressions`], but we can't use
+/// `find_all_ret_expressions` instead of this type. The reasons are:
+/// 1. `find_all_ret_expressions` passes the argument of `ExprKind::Ret` to a callback, but what we
+///    need here is `ExprKind::Ret` itself.
+/// 2. We can't trace current loop depth with `find_all_ret_expressions`.
 struct RetCollector {
     spans: Vec<Span>,
     ret_in_loop: bool,