@@ -802,6 +802,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
802
802
} ) ,
803
803
} ;
804
804
}
805
+ ty:: CoroutineClosure ( _, args) => {
806
+ return match args. as_coroutine_closure ( ) . upvar_tys ( ) . get ( field. index ( ) ) {
807
+ Some ( & ty) => Ok ( ty) ,
808
+ None => Err ( FieldAccessError :: OutOfRange {
809
+ field_count : args. as_coroutine_closure ( ) . upvar_tys ( ) . len ( ) ,
810
+ } ) ,
811
+ } ;
812
+ }
805
813
ty:: Coroutine ( _, args) => {
806
814
// Only prefix fields (upvars and current state) are
807
815
// accessible without a variant index.
@@ -1829,6 +1837,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1829
1837
} ) ,
1830
1838
}
1831
1839
}
1840
+ AggregateKind :: CoroutineClosure ( _, args) => {
1841
+ match args. as_coroutine_closure ( ) . upvar_tys ( ) . get ( field_index. as_usize ( ) ) {
1842
+ Some ( ty) => Ok ( * ty) ,
1843
+ None => Err ( FieldAccessError :: OutOfRange {
1844
+ field_count : args. as_coroutine_closure ( ) . upvar_tys ( ) . len ( ) ,
1845
+ } ) ,
1846
+ }
1847
+ }
1832
1848
AggregateKind :: Array ( ty) => Ok ( ty) ,
1833
1849
AggregateKind :: Tuple => {
1834
1850
unreachable ! ( "This should have been covered in check_rvalues" ) ;
@@ -2427,6 +2443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2427
2443
AggregateKind :: Tuple => None ,
2428
2444
AggregateKind :: Closure ( _, _) => None ,
2429
2445
AggregateKind :: Coroutine ( _, _) => None ,
2446
+ AggregateKind :: CoroutineClosure ( _, _) => None ,
2430
2447
} ,
2431
2448
}
2432
2449
}
@@ -2654,7 +2671,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2654
2671
// desugaring. A closure gets desugared to a struct, and
2655
2672
// these extra requirements are basically like where
2656
2673
// clauses on the struct.
2657
- AggregateKind :: Closure ( def_id, args) | AggregateKind :: Coroutine ( def_id, args) => {
2674
+ AggregateKind :: Closure ( def_id, args)
2675
+ | AggregateKind :: CoroutineClosure ( def_id, args)
2676
+ | AggregateKind :: Coroutine ( def_id, args) => {
2658
2677
( def_id, self . prove_closure_bounds ( tcx, def_id. expect_local ( ) , args, location) )
2659
2678
}
2660
2679
@@ -2697,10 +2716,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2697
2716
let typeck_root_args = ty:: GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
2698
2717
2699
2718
let parent_args = match tcx. def_kind ( def_id) {
2700
- DefKind :: Closure if tcx. is_coroutine ( def_id. to_def_id ( ) ) => {
2701
- args. as_coroutine ( ) . parent_args ( )
2719
+ DefKind :: Closure => {
2720
+ // FIXME(async_closures): It's kind of icky to access HIR here.
2721
+ match tcx. hir_node_by_def_id ( def_id) . expect_closure ( ) . kind {
2722
+ hir:: ClosureKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
2723
+ hir:: ClosureKind :: Coroutine ( _) => args. as_coroutine ( ) . parent_args ( ) ,
2724
+ hir:: ClosureKind :: CoroutineClosure ( _) => {
2725
+ args. as_coroutine_closure ( ) . parent_args ( )
2726
+ }
2727
+ }
2702
2728
}
2703
- DefKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
2704
2729
DefKind :: InlineConst => args. as_inline_const ( ) . parent_args ( ) ,
2705
2730
other => bug ! ( "unexpected item {:?}" , other) ,
2706
2731
} ;
0 commit comments