Skip to content

Commit ff27f90

Browse files
committed
Auto merge of rust-lang#107254 - chenyukang:yukang/fix-107113-wrong-sugg-in-macro, r=estebank
Avoid wrong code suggesting for attribute macro Fixes rust-lang#107113 r? `@estebank`
2 parents b07de24 + 0ff6579 commit ff27f90

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

clippy_lints/src/redundant_locals.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::is_from_proc_macro;
33
use clippy_utils::ty::needs_ordered_drop;
44
use rustc_hir::def::Res;
5-
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath};
5+
use rustc_hir::{
6+
BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath,
7+
};
68
use rustc_lint::{LateContext, LateLintPass, LintContext};
7-
use rustc_middle::lint::in_external_macro;
9+
use rustc_middle::lint::{in_external_macro, is_from_async_await};
810
use rustc_session::{declare_lint_pass, declare_tool_lint};
911
use rustc_span::symbol::Ident;
1012

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

95100
/// Check if a rebinding of a local affects the code's drop behavior.
96-
fn affects_drop_behavior<'tcx>(cx: &LateContext<'tcx>, bind: HirId, rebind: HirId, rebind_expr: &Expr<'tcx>) -> bool {
101+
fn affects_drop_behavior<'tcx>(
102+
cx: &LateContext<'tcx>,
103+
bind: HirId,
104+
rebind: HirId,
105+
rebind_expr: &Expr<'tcx>,
106+
) -> bool {
97107
let hir = cx.tcx.hir();
98108

99109
// the rebinding is in a different scope than the original binding

0 commit comments

Comments
 (0)