Fix invalid warning for closure in non-async function for needless_pass_by_ref_mut lint

This commit is contained in:
Guillaume Gomez 2023-10-06 11:11:57 +02:00
parent fe21991520
commit ec2b8ab83a

View File

@ -197,11 +197,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
}; };
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
if is_async {
let mut checked_closures = FxHashSet::default(); let mut checked_closures = FxHashSet::default();
// We retrieve all the closures declared in the async function because they will // We retrieve all the closures declared in the function because they will not be found
// not be found by `euv::Delegate`. // by `euv::Delegate`.
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default(); let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
for_each_expr_with_closures(cx, body, |expr| { for_each_expr_with_closures(cx, body, |expr| {
if let ExprKind::Closure(closure) = expr.kind { if let ExprKind::Closure(closure) = expr.kind {
@ -211,6 +211,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
}); });
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures); check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
if is_async {
while !ctx.async_closures.is_empty() { while !ctx.async_closures.is_empty() {
let async_closures = ctx.async_closures.clone(); let async_closures = ctx.async_closures.clone();
ctx.async_closures.clear(); ctx.async_closures.clear();