@@ -658,6 +658,24 @@ impl Pat {
658658 pub fn is_rest ( & self ) -> bool {
659659 matches ! ( self . kind, PatKind :: Rest )
660660 }
661+
662+ /// Whether this could be a never pattern, taking into account that a macro invocation can
663+ /// return a never pattern. Used to inform errors during parsing.
664+ pub fn could_be_never_pattern ( & self ) -> bool {
665+ let mut could_be_never_pattern = false ;
666+ self . walk ( & mut |pat| match & pat. kind {
667+ PatKind :: Never | PatKind :: MacCall ( _) => {
668+ could_be_never_pattern = true ;
669+ false
670+ }
671+ PatKind :: Or ( s) => {
672+ could_be_never_pattern = s. iter ( ) . all ( |p| p. could_be_never_pattern ( ) ) ;
673+ false
674+ }
675+ _ => true ,
676+ } ) ;
677+ could_be_never_pattern
678+ }
661679}
662680
663681/// A single field in a struct pattern.
@@ -1080,8 +1098,8 @@ pub struct Arm {
10801098 pub pat : P < Pat > ,
10811099 /// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
10821100 pub guard : Option < P < Expr > > ,
1083- /// Match arm body.
1084- pub body : P < Expr > ,
1101+ /// Match arm body. Omitted if the pattern is a never pattern.
1102+ pub body : Option < P < Expr > > ,
10851103 pub span : Span ,
10861104 pub id : NodeId ,
10871105 pub is_placeholder : bool ,
@@ -1311,7 +1329,7 @@ pub struct Closure {
13111329 pub binder : ClosureBinder ,
13121330 pub capture_clause : CaptureBy ,
13131331 pub constness : Const ,
1314- pub coro_kind : Option < CoroutineKind > ,
1332+ pub coroutine_kind : Option < CoroutineKind > ,
13151333 pub movability : Movability ,
13161334 pub fn_decl : P < FnDecl > ,
13171335 pub body : P < Expr > ,
@@ -1516,6 +1534,7 @@ pub enum ExprKind {
15161534pub enum GenBlockKind {
15171535 Async ,
15181536 Gen ,
1537+ AsyncGen ,
15191538}
15201539
15211540impl fmt:: Display for GenBlockKind {
@@ -1529,6 +1548,7 @@ impl GenBlockKind {
15291548 match self {
15301549 GenBlockKind :: Async => "async" ,
15311550 GenBlockKind :: Gen => "gen" ,
1551+ GenBlockKind :: AsyncGen => "async gen" ,
15321552 }
15331553 }
15341554}
@@ -2413,10 +2433,12 @@ pub enum Unsafe {
24132433/// Iterator`.
24142434#[ derive( Copy , Clone , Encodable , Decodable , Debug ) ]
24152435pub enum CoroutineKind {
2416- /// `async`, which evaluates to `impl Future`
2436+ /// `async`, which returns an `impl Future`
24172437 Async { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
2418- /// `gen`, which evaluates to `impl Iterator`
2438+ /// `gen`, which returns an `impl Iterator`
24192439 Gen { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
2440+ /// `async gen`, which returns an `impl AsyncIterator`
2441+ AsyncGen { span : Span , closure_id : NodeId , return_impl_trait_id : NodeId } ,
24202442}
24212443
24222444impl CoroutineKind {
@@ -2428,12 +2450,23 @@ impl CoroutineKind {
24282450 matches ! ( self , CoroutineKind :: Gen { .. } )
24292451 }
24302452
2453+ pub fn closure_id ( self ) -> NodeId {
2454+ match self {
2455+ CoroutineKind :: Async { closure_id, .. }
2456+ | CoroutineKind :: Gen { closure_id, .. }
2457+ | CoroutineKind :: AsyncGen { closure_id, .. } => closure_id,
2458+ }
2459+ }
2460+
24312461 /// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait`
24322462 /// item.
24332463 pub fn return_id ( self ) -> ( NodeId , Span ) {
24342464 match self {
24352465 CoroutineKind :: Async { return_impl_trait_id, span, .. }
2436- | CoroutineKind :: Gen { return_impl_trait_id, span, .. } => ( return_impl_trait_id, span) ,
2466+ | CoroutineKind :: Gen { return_impl_trait_id, span, .. }
2467+ | CoroutineKind :: AsyncGen { return_impl_trait_id, span, .. } => {
2468+ ( return_impl_trait_id, span)
2469+ }
24372470 }
24382471 }
24392472}
@@ -2838,7 +2871,7 @@ pub struct FnHeader {
28382871 /// The `unsafe` keyword, if any
28392872 pub unsafety : Unsafe ,
28402873 /// Whether this is `async`, `gen`, or nothing.
2841- pub coro_kind : Option < CoroutineKind > ,
2874+ pub coroutine_kind : Option < CoroutineKind > ,
28422875 /// The `const` keyword, if any
28432876 pub constness : Const ,
28442877 /// The `extern` keyword and corresponding ABI string, if any
@@ -2848,17 +2881,22 @@ pub struct FnHeader {
28482881impl FnHeader {
28492882 /// Does this function header have any qualifiers or is it empty?
28502883 pub fn has_qualifiers ( & self ) -> bool {
2851- let Self { unsafety, coro_kind , constness, ext } = self ;
2884+ let Self { unsafety, coroutine_kind , constness, ext } = self ;
28522885 matches ! ( unsafety, Unsafe :: Yes ( _) )
2853- || coro_kind . is_some ( )
2886+ || coroutine_kind . is_some ( )
28542887 || matches ! ( constness, Const :: Yes ( _) )
28552888 || !matches ! ( ext, Extern :: None )
28562889 }
28572890}
28582891
28592892impl Default for FnHeader {
28602893 fn default ( ) -> FnHeader {
2861- FnHeader { unsafety : Unsafe :: No , coro_kind : None , constness : Const :: No , ext : Extern :: None }
2894+ FnHeader {
2895+ unsafety : Unsafe :: No ,
2896+ coroutine_kind : None ,
2897+ constness : Const :: No ,
2898+ ext : Extern :: None ,
2899+ }
28622900 }
28632901}
28642902
0 commit comments