about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authoryanglsh <yanglsh@shanghaitech.edu.cn>2025-05-25 15:05:05 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2025-05-25 15:05:05 +0800
commit7ffc886472f7b3d452306f6d2ae8efc29bbad084 (patch)
treedee47884c740982e85643e94f946e5d1e1134e29 /clippy_lints
parentb6b97a741cad25bb9cd3250544b6fe06a1ab59cd (diff)
downloadrust-7ffc886472f7b3d452306f6d2ae8efc29bbad084.tar.gz
rust-7ffc886472f7b3d452306f6d2ae8efc29bbad084.zip
fix: `manual_find` suggests wrongly when return type needs adjustment
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/loops/manual_find.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs
index 35737f3eafe..f99989ec6ba 100644
--- a/clippy_lints/src/loops/manual_find.rs
+++ b/clippy_lints/src/loops/manual_find.rs
@@ -83,6 +83,13 @@ pub(super) fn check<'tcx>(
                 )[..],
             );
         }
+
+        // If the return type requires adjustments, we need to add a `.map` after the iterator
+        let inner_ret_adjust = cx.typeck_results().expr_adjustments(inner_ret);
+        if !inner_ret_adjust.is_empty() {
+            snippet.push_str(".map(|v| v as _)");
+        }
+
         // Extends to `last_stmt` to include semicolon in case of `return None;`
         let lint_span = span.to(last_stmt.span).to(last_ret.span);
         span_lint_and_then(