reasoning

This commit is contained in:
bendn 2024-03-21 05:48:16 +07:00
parent 22f57ff584
commit a356785065

View file

@ -68,7 +68,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
// e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop.
&& let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind
&& let body = cx.tcx.hir().body(body)
// Skip the lint if the body is not safe.
// Skip the lint if the body is not safe, so as not to suggest `for … in … unsafe {}`
// and suggesting `for … in … { unsafe { } }` is a little ugly.
&& let ExprKind::Block(Block { rules: BlockCheckMode::DefaultBlock, .. }, ..) = body.value.kind
{
let mut ret_collector = RetCollector::default();