@@ -658,6 +658,24 @@ impl Pat {
658
658
pub fn is_rest ( & self ) -> bool {
659
659
matches ! ( self . kind, PatKind :: Rest )
660
660
}
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
+ }
661
679
}
662
680
663
681
/// A single field in a struct pattern.
@@ -1080,8 +1098,8 @@ pub struct Arm {
1080
1098
pub pat : P < Pat > ,
1081
1099
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
1082
1100
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 > > ,
1085
1103
pub span : Span ,
1086
1104
pub id : NodeId ,
1087
1105
pub is_placeholder : bool ,
@@ -1311,7 +1329,7 @@ pub struct Closure {
1311
1329
pub binder : ClosureBinder ,
1312
1330
pub capture_clause : CaptureBy ,
1313
1331
pub constness : Const ,
1314
- pub coro_kind : Option < CoroutineKind > ,
1332
+ pub coroutine_kind : Option < CoroutineKind > ,
1315
1333
pub movability : Movability ,
1316
1334
pub fn_decl : P < FnDecl > ,
1317
1335
pub body : P < Expr > ,
@@ -1516,6 +1534,7 @@ pub enum ExprKind {
1516
1534
pub enum GenBlockKind {
1517
1535
Async ,
1518
1536
Gen ,
1537
+ AsyncGen ,
1519
1538
}
1520
1539
1521
1540
impl fmt:: Display for GenBlockKind {
@@ -1529,6 +1548,7 @@ impl GenBlockKind {
1529
1548
match self {
1530
1549
GenBlockKind :: Async => "async" ,
1531
1550
GenBlockKind :: Gen => "gen" ,
1551
+ GenBlockKind :: AsyncGen => "async gen" ,
1532
1552
}
1533
1553
}
1534
1554
}
@@ -2413,10 +2433,12 @@ pub enum Unsafe {
2413
2433
/// Iterator`.
2414
2434
#[ derive( Copy , Clone , Encodable , Decodable , Debug ) ]
2415
2435
pub enum CoroutineKind {
2416
- /// `async`, which evaluates to `impl Future`
2436
+ /// `async`, which returns an `impl Future`
2417
2437
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`
2419
2439
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 } ,
2420
2442
}
2421
2443
2422
2444
impl CoroutineKind {
@@ -2428,12 +2450,23 @@ impl CoroutineKind {
2428
2450
matches ! ( self , CoroutineKind :: Gen { .. } )
2429
2451
}
2430
2452
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
+
2431
2461
/// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait`
2432
2462
/// item.
2433
2463
pub fn return_id ( self ) -> ( NodeId , Span ) {
2434
2464
match self {
2435
2465
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
+ }
2437
2470
}
2438
2471
}
2439
2472
}
@@ -2838,7 +2871,7 @@ pub struct FnHeader {
2838
2871
/// The `unsafe` keyword, if any
2839
2872
pub unsafety : Unsafe ,
2840
2873
/// Whether this is `async`, `gen`, or nothing.
2841
- pub coro_kind : Option < CoroutineKind > ,
2874
+ pub coroutine_kind : Option < CoroutineKind > ,
2842
2875
/// The `const` keyword, if any
2843
2876
pub constness : Const ,
2844
2877
/// The `extern` keyword and corresponding ABI string, if any
@@ -2848,17 +2881,22 @@ pub struct FnHeader {
2848
2881
impl FnHeader {
2849
2882
/// Does this function header have any qualifiers or is it empty?
2850
2883
pub fn has_qualifiers ( & self ) -> bool {
2851
- let Self { unsafety, coro_kind , constness, ext } = self ;
2884
+ let Self { unsafety, coroutine_kind , constness, ext } = self ;
2852
2885
matches ! ( unsafety, Unsafe :: Yes ( _) )
2853
- || coro_kind . is_some ( )
2886
+ || coroutine_kind . is_some ( )
2854
2887
|| matches ! ( constness, Const :: Yes ( _) )
2855
2888
|| !matches ! ( ext, Extern :: None )
2856
2889
}
2857
2890
}
2858
2891
2859
2892
impl Default for FnHeader {
2860
2893
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
+ }
2862
2900
}
2863
2901
}
2864
2902
0 commit comments