@@ -3,8 +3,9 @@ use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt};
33use rustc_errors:: Applicability ;
44use rustc_hir:: intravisit:: FnKind ;
55use rustc_hir:: {
6- Block , Body , Closure , CoroutineKind , CoroutineSource , CoroutineDesugaring , Expr , ExprKind , FnDecl , FnRetTy , GenericArg , GenericBound ,
7- ImplItem , Item , ItemKind , LifetimeName , Node , Term , TraitRef , Ty , TyKind , TypeBindingKind ,
6+ Block , Body , Closure , CoroutineDesugaring , CoroutineKind , CoroutineSource , Expr , ExprKind , FnDecl , FnRetTy ,
7+ GenericArg , GenericBound , ImplItem , Item , ItemKind , LifetimeName , Node , Term , TraitRef , Ty , TyKind ,
8+ TypeBindingKind , ClosureKind ,
89} ;
910use rustc_lint:: { LateContext , LateLintPass } ;
1011use rustc_session:: declare_lint_pass;
@@ -171,16 +172,25 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
171172 . all ( |in_lt| output_lifetimes. iter ( ) . any ( |out_lt| in_lt == out_lt) )
172173}
173174
174- fn desugared_async_block < ' tcx > ( cx : & LateContext < ' tcx > , block : & ' tcx Block < ' tcx > ) -> Option < & ' tcx Body < ' tcx > > {
175- if let Some ( block_expr) = block. expr
176- && let Expr {
177- kind : ExprKind :: Closure ( & Closure { body, .. } ) ,
178- ..
179- } = block_expr
180- && let closure_body = cx. tcx . hir ( ) . body ( body)
181- && closure_body. coroutine_kind == Some ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , CoroutineSource :: Block ) )
175+ fn desugared_async_block < ' tcx > (
176+ cx : & LateContext < ' tcx > ,
177+ block : & ' tcx Block < ' tcx > ,
178+ ) -> Option < & ' tcx Body < ' tcx > > {
179+ if let Some ( Expr {
180+ kind :
181+ ExprKind :: Closure ( & Closure {
182+ kind :
183+ ClosureKind :: Coroutine ( CoroutineKind :: Desugared (
184+ CoroutineDesugaring :: Async ,
185+ CoroutineSource :: Block ,
186+ ) ) ,
187+ body,
188+ ..
189+ } ) ,
190+ ..
191+ } ) = block. expr
182192 {
183- return Some ( closure_body ) ;
193+ return Some ( cx . tcx . hir ( ) . body ( body ) ) ;
184194 }
185195
186196 None
0 commit comments