@@ -106,10 +106,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
106
106
use rustc_hir:: intravisit:: { FnKind , Visitor , walk_expr} ;
107
107
use rustc_hir:: {
108
108
self as hir, Arm , BindingMode , Block , BlockCheckMode , Body , ByRef , Closure , ConstArgKind , ConstContext ,
109
- Destination , Expr , ExprField , ExprKind , FnDecl , FnRetTy , GenericArg , GenericArgs , HirId , Impl , ImplItem ,
110
- ImplItemKind , ImplItemRef , Item , ItemKind , LangItem , LetStmt , MatchSource , Mutability , Node , OwnerId , OwnerNode ,
111
- Param , Pat , PatExpr , PatExprKind , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitFn , TraitItem ,
112
- TraitItemKind , TraitItemRef , TraitRef , TyKind , UnOp , def,
109
+ CoroutineDesugaring , CoroutineKind , Destination , Expr , ExprField , ExprKind , FnDecl , FnRetTy , GenericArg ,
110
+ GenericArgs , HirId , Impl , ImplItem , ImplItemKind , ImplItemRef , Item , ItemKind , LangItem , LetStmt , MatchSource ,
111
+ Mutability , Node , OwnerId , OwnerNode , Param , Pat , PatExpr , PatExprKind , PatKind , Path , PathSegment , PrimTy , QPath ,
112
+ Stmt , StmtKind , TraitFn , TraitItem , TraitItemKind , TraitItemRef , TraitRef , TyKind , UnOp , def,
113
113
} ;
114
114
use rustc_lexer:: { TokenKind , tokenize} ;
115
115
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
@@ -2137,28 +2137,35 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool {
2137
2137
}
2138
2138
}
2139
2139
2140
- /// Peels away all the compiler generated code surrounding the body of an async function,
2141
- pub fn get_async_fn_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2142
- if let ExprKind :: Closure ( & Closure { body, .. } ) = body. value . kind {
2143
- if let ExprKind :: Block (
2140
+ /// Peels away all the compiler generated code surrounding the body of an async closure.
2141
+ pub fn get_async_closure_expr < ' tcx > ( tcx : TyCtxt < ' tcx > , expr : & Expr < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2142
+ if let ExprKind :: Closure ( & Closure {
2143
+ body,
2144
+ kind : hir:: ClosureKind :: Coroutine ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) ,
2145
+ ..
2146
+ } ) = expr. kind
2147
+ && let ExprKind :: Block (
2144
2148
Block {
2145
- stmts : [ ] ,
2146
2149
expr :
2147
2150
Some ( Expr {
2148
- kind : ExprKind :: DropTemps ( expr ) ,
2151
+ kind : ExprKind :: DropTemps ( inner_expr ) ,
2149
2152
..
2150
2153
} ) ,
2151
2154
..
2152
2155
} ,
2153
2156
_,
2154
2157
) = tcx. hir_body ( body) . value . kind
2155
- {
2156
- return Some ( expr) ;
2157
- }
2158
+ {
2159
+ return Some ( inner_expr) ;
2158
2160
}
2159
2161
None
2160
2162
}
2161
2163
2164
+ /// Peels away all the compiler generated code surrounding the body of an async function.
2165
+ pub fn get_async_fn_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2166
+ get_async_closure_expr ( tcx, body. value )
2167
+ }
2168
+
2162
2169
// check if expr is calling method or function with #[must_use] attribute
2163
2170
pub fn is_must_use_func_call ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
2164
2171
let did = match expr. kind {
0 commit comments