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