@@ -808,6 +808,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
808808 } ) ,
809809 } ;
810810 }
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+ }
811819 ty:: Coroutine ( _, args) => {
812820 // Only prefix fields (upvars and current state) are
813821 // accessible without a variant index.
@@ -1875,6 +1883,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18751883 } ) ,
18761884 }
18771885 }
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+ }
18781894 AggregateKind :: Array ( ty) => Ok ( ty) ,
18791895 AggregateKind :: Tuple => {
18801896 unreachable ! ( "This should have been covered in check_rvalues" ) ;
@@ -2478,6 +2494,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24782494 AggregateKind :: Tuple => None ,
24792495 AggregateKind :: Closure ( _, _) => None ,
24802496 AggregateKind :: Coroutine ( _, _) => None ,
2497+ AggregateKind :: CoroutineClosure ( _, _) => None ,
24812498 } ,
24822499 }
24832500 }
@@ -2705,7 +2722,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27052722 // desugaring. A closure gets desugared to a struct, and
27062723 // these extra requirements are basically like where
27072724 // 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) => (
27092728 def_id,
27102729 self . prove_closure_bounds (
27112730 tcx,
@@ -2754,10 +2773,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27542773 let typeck_root_args = ty:: GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
27552774
27562775 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+ }
27592785 }
2760- DefKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
27612786 DefKind :: InlineConst => args. as_inline_const ( ) . parent_args ( ) ,
27622787 other => bug ! ( "unexpected item {:?}" , other) ,
27632788 } ;
0 commit comments