@@ -1311,7 +1311,7 @@ pub struct Closure {
13111311 pub binder : ClosureBinder ,
13121312 pub capture_clause : CaptureBy ,
13131313 pub constness : Const ,
1314- pub asyncness : Async ,
1314+ pub coro_kind : Option < CoroutineKind > ,
13151315 pub movability : Movability ,
13161316 pub fn_decl : P < FnDecl > ,
13171317 pub body : P < Expr > ,
@@ -2406,28 +2406,34 @@ pub enum Unsafe {
24062406 No ,
24072407}
24082408
2409+ /// Describes what kind of coroutine markers, if any, a function has.
2410+ ///
2411+ /// Coroutine markers are things that cause the function to generate a coroutine, such as `async`,
2412+ /// which makes the function return `impl Future`, or `gen`, which makes the function return `impl
2413+ /// Iterator`.
24092414#[ derive( Copy , Clone , Encodable , Decodable , Debug ) ]
2410- pub enum Async {
2411- Yes { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
2412- No ,
2415+ pub enum CoroutineKind {
2416+ /// `async`, which evaluates to `impl Future`
2417+ Async { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
2418+ /// `gen`, which evaluates to `impl Iterator`
2419+ Gen { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
24132420}
24142421
2415- #[ derive( Copy , Clone , Encodable , Decodable , Debug ) ]
2416- pub enum Gen {
2417- Yes { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
2418- No ,
2419- }
2420-
2421- impl Async {
2422+ impl CoroutineKind {
24222423 pub fn is_async ( self ) -> bool {
2423- matches ! ( self , Async :: Yes { .. } )
2424+ matches ! ( self , CoroutineKind :: Async { .. } )
2425+ }
2426+
2427+ pub fn is_gen ( self ) -> bool {
2428+ matches ! ( self , CoroutineKind :: Gen { .. } )
24242429 }
24252430
2426- /// In this case this is an `async` return, the `NodeId` for the generated `impl Trait` item.
2427- pub fn opt_return_id ( self ) -> Option < ( NodeId , Span ) > {
2431+ /// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait`
2432+ /// item.
2433+ pub fn return_id ( self ) -> ( NodeId , Span ) {
24282434 match self {
2429- Async :: Yes { return_impl_trait_id, span, .. } => Some ( ( return_impl_trait_id , span ) ) ,
2430- Async :: No => None ,
2435+ CoroutineKind :: Async { return_impl_trait_id, span, .. }
2436+ | CoroutineKind :: Gen { return_impl_trait_id , span , .. } => ( return_impl_trait_id , span ) ,
24312437 }
24322438 }
24332439}
@@ -2831,8 +2837,8 @@ impl Extern {
28312837pub struct FnHeader {
28322838 /// The `unsafe` keyword, if any
28332839 pub unsafety : Unsafe ,
2834- /// The `async` keyword, if any
2835- pub asyncness : Async ,
2840+ /// Whether this is `async`, `gen`, or nothing.
2841+ pub coro_kind : Option < CoroutineKind > ,
28362842 /// The `const` keyword, if any
28372843 pub constness : Const ,
28382844 /// The `extern` keyword and corresponding ABI string, if any
@@ -2842,22 +2848,17 @@ pub struct FnHeader {
28422848impl FnHeader {
28432849 /// Does this function header have any qualifiers or is it empty?
28442850 pub fn has_qualifiers ( & self ) -> bool {
2845- let Self { unsafety, asyncness , constness, ext } = self ;
2851+ let Self { unsafety, coro_kind , constness, ext } = self ;
28462852 matches ! ( unsafety, Unsafe :: Yes ( _) )
2847- || asyncness . is_async ( )
2853+ || coro_kind . is_some ( )
28482854 || matches ! ( constness, Const :: Yes ( _) )
28492855 || !matches ! ( ext, Extern :: None )
28502856 }
28512857}
28522858
28532859impl Default for FnHeader {
28542860 fn default ( ) -> FnHeader {
2855- FnHeader {
2856- unsafety : Unsafe :: No ,
2857- asyncness : Async :: No ,
2858- constness : Const :: No ,
2859- ext : Extern :: None ,
2860- }
2861+ FnHeader { unsafety : Unsafe :: No , coro_kind : None , constness : Const :: No , ext : Extern :: None }
28612862 }
28622863}
28632864
@@ -3177,7 +3178,7 @@ mod size_asserts {
31773178 static_assert_size ! ( Block , 32 ) ;
31783179 static_assert_size ! ( Expr , 72 ) ;
31793180 static_assert_size ! ( ExprKind , 40 ) ;
3180- static_assert_size ! ( Fn , 152 ) ;
3181+ static_assert_size ! ( Fn , 160 ) ;
31813182 static_assert_size ! ( ForeignItem , 96 ) ;
31823183 static_assert_size ! ( ForeignItemKind , 24 ) ;
31833184 static_assert_size ! ( GenericArg , 24 ) ;
0 commit comments