@@ -2,9 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_help;
2
2
use clippy_utils:: is_from_proc_macro;
3
3
use clippy_utils:: ty:: needs_ordered_drop;
4
4
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
+ } ;
6
8
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 } ;
8
10
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
9
11
use rustc_span:: symbol:: Ident ;
10
12
@@ -65,6 +67,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
65
67
// the local is user-controlled
66
68
if !in_external_macro( cx. sess( ) , local. span) ;
67
69
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) ;
68
73
then {
69
74
span_lint_and_help(
70
75
cx,
@@ -93,7 +98,12 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingAnnotation> {
93
98
}
94
99
95
100
/// 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 {
97
107
let hir = cx. tcx . hir ( ) ;
98
108
99
109
// the rebinding is in a different scope than the original binding
0 commit comments