@@ -2394,18 +2394,15 @@ impl<'a> Parser<'a> {
2394
2394
let constness = self . parse_constness ( case) ;
2395
2395
2396
2396
let async_start_sp = self . token . span ;
2397
- let asyncness = self . parse_asyncness ( case) ;
2398
-
2399
- let _gen_start_sp = self . token . span ;
2400
- let genness = self . parse_genness ( case) ;
2397
+ let coroutine_kind = self . parse_coroutine_kind ( case) ;
2401
2398
2402
2399
let unsafe_start_sp = self . token . span ;
2403
2400
let unsafety = self . parse_unsafety ( case) ;
2404
2401
2405
2402
let ext_start_sp = self . token . span ;
2406
2403
let ext = self . parse_extern ( case) ;
2407
2404
2408
- if let Some ( CoroutineKind :: Async { span, .. } ) = asyncness {
2405
+ if let Some ( CoroutineKind :: Async { span, .. } ) = coroutine_kind {
2409
2406
if span. is_rust_2015 ( ) {
2410
2407
self . sess . emit_err ( errors:: AsyncFnIn2015 {
2411
2408
span,
@@ -2414,16 +2411,11 @@ impl<'a> Parser<'a> {
2414
2411
}
2415
2412
}
2416
2413
2417
- if let Some ( CoroutineKind :: Gen { span, .. } ) = genness {
2418
- self . sess . gated_spans . gate ( sym:: gen_blocks, span) ;
2419
- }
2420
-
2421
- if let (
2422
- Some ( CoroutineKind :: Async { span : async_span, .. } ) ,
2423
- Some ( CoroutineKind :: Gen { span : gen_span, .. } ) ,
2424
- ) = ( asyncness, genness)
2425
- {
2426
- self . sess . emit_err ( errors:: AsyncGenFn { span : async_span. to ( gen_span) } ) ;
2414
+ match coroutine_kind {
2415
+ Some ( CoroutineKind :: Gen { span, .. } ) | Some ( CoroutineKind :: AsyncGen { span, .. } ) => {
2416
+ self . sess . gated_spans . gate ( sym:: gen_blocks, span) ;
2417
+ }
2418
+ Some ( CoroutineKind :: Async { .. } ) | None => { }
2427
2419
}
2428
2420
2429
2421
if !self . eat_keyword_case ( kw:: Fn , case) {
@@ -2442,7 +2434,7 @@ impl<'a> Parser<'a> {
2442
2434
2443
2435
// We may be able to recover
2444
2436
let mut recover_constness = constness;
2445
- let mut recover_asyncness = asyncness ;
2437
+ let mut recover_coroutine_kind = coroutine_kind ;
2446
2438
let mut recover_unsafety = unsafety;
2447
2439
// This will allow the machine fix to directly place the keyword in the correct place or to indicate
2448
2440
// that the keyword is already present and the second instance should be removed.
@@ -2455,15 +2447,24 @@ impl<'a> Parser<'a> {
2455
2447
}
2456
2448
}
2457
2449
} else if self . check_keyword ( kw:: Async ) {
2458
- match asyncness {
2450
+ match coroutine_kind {
2459
2451
Some ( CoroutineKind :: Async { span, .. } ) => {
2460
2452
Some ( WrongKw :: Duplicated ( span) )
2461
2453
}
2454
+ Some ( CoroutineKind :: AsyncGen { span, .. } ) => {
2455
+ Some ( WrongKw :: Duplicated ( span) )
2456
+ }
2462
2457
Some ( CoroutineKind :: Gen { .. } ) => {
2463
- panic ! ( "not sure how to recover here" )
2458
+ recover_coroutine_kind = Some ( CoroutineKind :: AsyncGen {
2459
+ span : self . token . span ,
2460
+ closure_id : DUMMY_NODE_ID ,
2461
+ return_impl_trait_id : DUMMY_NODE_ID ,
2462
+ } ) ;
2463
+ // FIXME(gen_blocks): This span is wrong, didn't want to think about it.
2464
+ Some ( WrongKw :: Misplaced ( unsafe_start_sp) )
2464
2465
}
2465
2466
None => {
2466
- recover_asyncness = Some ( CoroutineKind :: Async {
2467
+ recover_coroutine_kind = Some ( CoroutineKind :: Async {
2467
2468
span : self . token . span ,
2468
2469
closure_id : DUMMY_NODE_ID ,
2469
2470
return_impl_trait_id : DUMMY_NODE_ID ,
@@ -2561,7 +2562,7 @@ impl<'a> Parser<'a> {
2561
2562
return Ok ( FnHeader {
2562
2563
constness : recover_constness,
2563
2564
unsafety : recover_unsafety,
2564
- coroutine_kind : recover_asyncness ,
2565
+ coroutine_kind : recover_coroutine_kind ,
2565
2566
ext,
2566
2567
} ) ;
2567
2568
}
@@ -2571,12 +2572,6 @@ impl<'a> Parser<'a> {
2571
2572
}
2572
2573
}
2573
2574
2574
- let coroutine_kind = match asyncness {
2575
- Some ( CoroutineKind :: Async { .. } ) => asyncness,
2576
- Some ( CoroutineKind :: Gen { .. } ) => unreachable ! ( "asycness cannot be Gen" ) ,
2577
- None => genness,
2578
- } ;
2579
-
2580
2575
Ok ( FnHeader { constness, unsafety, coroutine_kind, ext } )
2581
2576
}
2582
2577
0 commit comments