@@ -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 : CoroutineKind ,
13151315 pub movability : Movability ,
13161316 pub fn_decl : P < FnDecl > ,
13171317 pub body : P < Expr > ,
@@ -2406,28 +2406,38 @@ 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 ,
2413- }
2414-
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 ,
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 } ,
2420+ /// Neither `async` nor `gen`
2421+ None ,
24192422}
24202423
2421- impl Async {
2424+ impl CoroutineKind {
24222425 pub fn is_async ( self ) -> bool {
2423- matches ! ( self , Async :: Yes { .. } )
2426+ matches ! ( self , CoroutineKind :: Async { .. } )
2427+ }
2428+
2429+ pub fn is_gen ( self ) -> bool {
2430+ matches ! ( self , CoroutineKind :: Gen { .. } )
24242431 }
24252432
24262433 /// In this case this is an `async` return, the `NodeId` for the generated `impl Trait` item.
24272434 pub fn opt_return_id ( self ) -> Option < ( NodeId , Span ) > {
24282435 match self {
2429- Async :: Yes { return_impl_trait_id, span, .. } => Some ( ( return_impl_trait_id, span) ) ,
2430- Async :: No => None ,
2436+ CoroutineKind :: Async { return_impl_trait_id, span, .. }
2437+ | CoroutineKind :: Gen { return_impl_trait_id, span, .. } => {
2438+ Some ( ( return_impl_trait_id, span) )
2439+ }
2440+ CoroutineKind :: None => None ,
24312441 }
24322442 }
24332443}
@@ -2831,36 +2841,32 @@ impl Extern {
28312841pub struct FnHeader {
28322842 /// The `unsafe` keyword, if any
28332843 pub unsafety : Unsafe ,
2834- /// The `async` keyword, if any
2835- pub asyncness : Async ,
2844+ /// Whether this is `async`, `gen`, or nothing.
2845+ pub coro_kind : CoroutineKind ,
28362846 /// The `const` keyword, if any
28372847 pub constness : Const ,
28382848 /// The `extern` keyword and corresponding ABI string, if any
28392849 pub ext : Extern ,
2840- /// The `gen` keyword, if any
2841- pub genness : Gen ,
28422850}
28432851
28442852impl FnHeader {
28452853 /// Does this function header have any qualifiers or is it empty?
28462854 pub fn has_qualifiers ( & self ) -> bool {
2847- let Self { unsafety, asyncness , constness, ext, genness } = self ;
2855+ let Self { unsafety, coro_kind , constness, ext } = self ;
28482856 matches ! ( unsafety, Unsafe :: Yes ( _) )
2849- || asyncness . is_async ( )
2857+ || ! matches ! ( coro_kind , CoroutineKind :: None )
28502858 || matches ! ( constness, Const :: Yes ( _) )
28512859 || !matches ! ( ext, Extern :: None )
2852- || matches ! ( genness, Gen :: Yes { .. } )
28532860 }
28542861}
28552862
28562863impl Default for FnHeader {
28572864 fn default ( ) -> FnHeader {
28582865 FnHeader {
28592866 unsafety : Unsafe :: No ,
2860- asyncness : Async :: No ,
2867+ coro_kind : CoroutineKind :: None ,
28612868 constness : Const :: No ,
28622869 ext : Extern :: None ,
2863- genness : Gen :: No ,
28642870 }
28652871 }
28662872}
@@ -3181,7 +3187,7 @@ mod size_asserts {
31813187 static_assert_size ! ( Block , 32 ) ;
31823188 static_assert_size ! ( Expr , 72 ) ;
31833189 static_assert_size ! ( ExprKind , 40 ) ;
3184- static_assert_size ! ( Fn , 168 ) ;
3190+ static_assert_size ! ( Fn , 160 ) ;
31853191 static_assert_size ! ( ForeignItem , 96 ) ;
31863192 static_assert_size ! ( ForeignItemKind , 24 ) ;
31873193 static_assert_size ! ( GenericArg , 24 ) ;
0 commit comments