@@ -808,6 +808,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
808
808
} ) ,
809
809
} ;
810
810
}
811
+ ty:: CoroutineClosure ( _, args) => {
812
+ return match args. as_coroutine_closure ( ) . upvar_tys ( ) . get ( field. index ( ) ) {
813
+ Some ( & ty) => Ok ( ty) ,
814
+ None => Err ( FieldAccessError :: OutOfRange {
815
+ field_count : args. as_coroutine_closure ( ) . upvar_tys ( ) . len ( ) ,
816
+ } ) ,
817
+ } ;
818
+ }
811
819
ty:: Coroutine ( _, args) => {
812
820
// Only prefix fields (upvars and current state) are
813
821
// accessible without a variant index.
@@ -1875,6 +1883,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1875
1883
} ) ,
1876
1884
}
1877
1885
}
1886
+ AggregateKind :: CoroutineClosure ( _, args) => {
1887
+ match args. as_coroutine_closure ( ) . upvar_tys ( ) . get ( field_index. as_usize ( ) ) {
1888
+ Some ( ty) => Ok ( * ty) ,
1889
+ None => Err ( FieldAccessError :: OutOfRange {
1890
+ field_count : args. as_coroutine_closure ( ) . upvar_tys ( ) . len ( ) ,
1891
+ } ) ,
1892
+ }
1893
+ }
1878
1894
AggregateKind :: Array ( ty) => Ok ( ty) ,
1879
1895
AggregateKind :: Tuple => {
1880
1896
unreachable ! ( "This should have been covered in check_rvalues" ) ;
@@ -2478,6 +2494,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2478
2494
AggregateKind :: Tuple => None ,
2479
2495
AggregateKind :: Closure ( _, _) => None ,
2480
2496
AggregateKind :: Coroutine ( _, _) => None ,
2497
+ AggregateKind :: CoroutineClosure ( _, _) => None ,
2481
2498
} ,
2482
2499
}
2483
2500
}
@@ -2705,7 +2722,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2705
2722
// desugaring. A closure gets desugared to a struct, and
2706
2723
// these extra requirements are basically like where
2707
2724
// clauses on the struct.
2708
- AggregateKind :: Closure ( def_id, args) | AggregateKind :: Coroutine ( def_id, args) => (
2725
+ AggregateKind :: Closure ( def_id, args)
2726
+ | AggregateKind :: CoroutineClosure ( def_id, args)
2727
+ | AggregateKind :: Coroutine ( def_id, args) => (
2709
2728
def_id,
2710
2729
self . prove_closure_bounds (
2711
2730
tcx,
@@ -2754,10 +2773,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2754
2773
let typeck_root_args = ty:: GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
2755
2774
2756
2775
let parent_args = match tcx. def_kind ( def_id) {
2757
- DefKind :: Closure if tcx. is_coroutine ( def_id. to_def_id ( ) ) => {
2758
- args. as_coroutine ( ) . parent_args ( )
2776
+ DefKind :: Closure => {
2777
+ // FIXME(async_closures): It's kind of icky to access HIR here.
2778
+ match tcx. hir_node_by_def_id ( def_id) . expect_closure ( ) . kind {
2779
+ hir:: ClosureKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
2780
+ hir:: ClosureKind :: Coroutine ( _) => args. as_coroutine ( ) . parent_args ( ) ,
2781
+ hir:: ClosureKind :: CoroutineClosure ( _) => {
2782
+ args. as_coroutine_closure ( ) . parent_args ( )
2783
+ }
2784
+ }
2759
2785
}
2760
- DefKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
2761
2786
DefKind :: InlineConst => args. as_inline_const ( ) . parent_args ( ) ,
2762
2787
other => bug ! ( "unexpected item {:?}" , other) ,
2763
2788
} ;
0 commit comments