Skip to content

Commit ec2b8ab

Browse files
Fix invalid warning for closure in non-async function for needless_pass_by_ref_mut lint
1 parent fe21991 commit ec2b8ab

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

clippy_lints/src/needless_pass_by_ref_mut.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,21 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
197197
};
198198
let infcx = cx.tcx.infer_ctxt().build();
199199
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
200-
if is_async {
201-
let mut checked_closures = FxHashSet::default();
202-
203-
// We retrieve all the closures declared in the async function because they will
204-
// not be found by `euv::Delegate`.
205-
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
206-
for_each_expr_with_closures(cx, body, |expr| {
207-
if let ExprKind::Closure(closure) = expr.kind {
208-
closures.insert(closure.def_id);
209-
}
210-
ControlFlow::<()>::Continue(())
211-
});
212-
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
213200

201+
let mut checked_closures = FxHashSet::default();
202+
203+
// We retrieve all the closures declared in the function because they will not be found
204+
// by `euv::Delegate`.
205+
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
206+
for_each_expr_with_closures(cx, body, |expr| {
207+
if let ExprKind::Closure(closure) = expr.kind {
208+
closures.insert(closure.def_id);
209+
}
210+
ControlFlow::<()>::Continue(())
211+
});
212+
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
213+
214+
if is_async {
214215
while !ctx.async_closures.is_empty() {
215216
let async_closures = ctx.async_closures.clone();
216217
ctx.async_closures.clear();

0 commit comments

Comments
 (0)