Skip to content

Commit

Permalink
fix RedundantLocals clippy caused by async and await
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Aug 2, 2023
1 parent b0e64a9 commit 0ff6579
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions clippy_lints/src/redundant_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::needs_ordered_drop;
use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath};
use rustc_hir::{
BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::lint::{in_external_macro, is_from_async_await};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::Ident;

Expand Down Expand Up @@ -65,6 +67,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
// the local is user-controlled
if !in_external_macro(cx.sess(), local.span);
if !is_from_proc_macro(cx, expr);
// Async function parameters are lowered into the closure body, so we can't lint them.
// see `lower_maybe_async_body` in `rust_ast_lowering`
if !is_from_async_await(local.span);
then {
span_lint_and_help(
cx,
Expand Down Expand Up @@ -93,7 +98,12 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingAnnotation> {
}

/// Check if a rebinding of a local affects the code's drop behavior.
fn affects_drop_behavior<'tcx>(cx: &LateContext<'tcx>, bind: HirId, rebind: HirId, rebind_expr: &Expr<'tcx>) -> bool {
fn affects_drop_behavior<'tcx>(
cx: &LateContext<'tcx>,
bind: HirId,
rebind: HirId,
rebind_expr: &Expr<'tcx>,
) -> bool {
let hir = cx.tcx.hir();

// the rebinding is in a different scope than the original binding
Expand Down

0 comments on commit 0ff6579

Please sign in to comment.