@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22use clippy_utils:: source:: snippet;
33use clippy_utils:: ty:: implements_trait;
44use rustc_errors:: Applicability ;
5- use rustc_hir:: { Body , BodyId , CoroutineKind , CoroutineSource , ExprKind , QPath } ;
5+ use rustc_hir:: { Closure , ClosureKind , CoroutineDesugaring , CoroutineKind , CoroutineSource , Expr , ExprKind , QPath } ;
66use rustc_lint:: { LateContext , LateLintPass } ;
77use rustc_session:: declare_lint_pass;
88
@@ -44,16 +44,22 @@ declare_clippy_lint! {
4444declare_lint_pass ! ( AsyncYieldsAsync => [ ASYNC_YIELDS_ASYNC ] ) ;
4545
4646impl < ' tcx > LateLintPass < ' tcx > for AsyncYieldsAsync {
47- fn check_body ( & mut self , cx : & LateContext < ' tcx > , body : & ' tcx Body < ' _ > ) {
48- use CoroutineSource :: { Block , Closure } ;
47+ fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
4948 // For functions, with explicitly defined types, don't warn.
5049 // XXXkhuey maybe we should?
51- if let Some ( CoroutineKind :: Async ( Block | Closure ) ) = body. coroutine_kind {
50+ if let ExprKind :: Closure ( Closure {
51+ kind :
52+ ClosureKind :: Coroutine ( CoroutineKind :: Desugared (
53+ CoroutineDesugaring :: Async ,
54+ CoroutineSource :: Block | CoroutineSource :: Closure ,
55+ ) ) ,
56+ body : body_id,
57+ ..
58+ } ) = expr. kind
59+ {
5260 if let Some ( future_trait_def_id) = cx. tcx . lang_items ( ) . future_trait ( ) {
53- let body_id = BodyId {
54- hir_id : body. value . hir_id ,
55- } ;
56- let typeck_results = cx. tcx . typeck_body ( body_id) ;
61+ let typeck_results = cx. tcx . typeck_body ( * body_id) ;
62+ let body = cx. tcx . hir ( ) . body ( * body_id) ;
5763 let expr_ty = typeck_results. expr_ty ( body. value ) ;
5864
5965 if implements_trait ( cx, expr_ty, future_trait_def_id, & [ ] ) {
0 commit comments