@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
2
2
use clippy_utils:: source:: snippet;
3
3
use clippy_utils:: ty:: implements_trait;
4
4
use 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 } ;
6
6
use rustc_lint:: { LateContext , LateLintPass } ;
7
7
use rustc_session:: declare_lint_pass;
8
8
@@ -44,16 +44,22 @@ declare_clippy_lint! {
44
44
declare_lint_pass ! ( AsyncYieldsAsync => [ ASYNC_YIELDS_ASYNC ] ) ;
45
45
46
46
impl < ' 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 > ) {
49
48
// For functions, with explicitly defined types, don't warn.
50
49
// 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
+ {
52
60
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) ;
57
63
let expr_ty = typeck_results. expr_ty ( body. value ) ;
58
64
59
65
if implements_trait ( cx, expr_ty, future_trait_def_id, & [ ] ) {
0 commit comments