@@ -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 } ;
@@ -2134,25 +2134,34 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool {
2134
2134
}
2135
2135
}
2136
2136
2137
- /// Peels away all the compiler generated code surrounding the body of an async function,
2138
- pub fn get_async_fn_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2139
- if let ExprKind :: Closure ( & Closure { body, .. } ) = body. value . kind
2137
+ /// Peels away all the compiler generated code surrounding the body of an async closure.
2138
+ pub fn get_async_closure_expr < ' tcx > ( tcx : TyCtxt < ' tcx > , expr : & Expr < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2139
+ if let ExprKind :: Closure ( & Closure {
2140
+ body,
2141
+ kind : hir:: ClosureKind :: Coroutine ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) ,
2142
+ ..
2143
+ } ) = expr. kind
2140
2144
&& let ExprKind :: Block (
2141
2145
Block {
2142
- stmts : [ ] ,
2143
2146
expr :
2144
2147
Some ( Expr {
2145
- kind : ExprKind :: DropTemps ( expr ) ,
2148
+ kind : ExprKind :: DropTemps ( inner_expr ) ,
2146
2149
..
2147
2150
} ) ,
2148
2151
..
2149
2152
} ,
2150
2153
_,
2151
2154
) = tcx. hir_body ( body) . value . kind
2152
2155
{
2153
- return Some ( expr) ;
2156
+ Some ( inner_expr)
2157
+ } else {
2158
+ None
2154
2159
}
2155
- None
2160
+ }
2161
+
2162
+ /// Peels away all the compiler generated code surrounding the body of an async function,
2163
+ pub fn get_async_fn_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' _ > ) -> Option < & ' tcx Expr < ' tcx > > {
2164
+ get_async_closure_expr ( tcx, body. value )
2156
2165
}
2157
2166
2158
2167
// check if expr is calling method or function with #[must_use] attribute
0 commit comments