@@ -802,6 +802,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
802802 } ) ,
803803 } ;
804804 }
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+ }
805813 ty:: Coroutine ( _, args) => {
806814 // Only prefix fields (upvars and current state) are
807815 // accessible without a variant index.
@@ -1829,6 +1837,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18291837 } ) ,
18301838 }
18311839 }
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+ }
18321848 AggregateKind :: Array ( ty) => Ok ( ty) ,
18331849 AggregateKind :: Tuple => {
18341850 unreachable ! ( "This should have been covered in check_rvalues" ) ;
@@ -2427,6 +2443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24272443 AggregateKind :: Tuple => None ,
24282444 AggregateKind :: Closure ( _, _) => None ,
24292445 AggregateKind :: Coroutine ( _, _) => None ,
2446+ AggregateKind :: CoroutineClosure ( _, _) => None ,
24302447 } ,
24312448 }
24322449 }
@@ -2654,7 +2671,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26542671 // desugaring. A closure gets desugared to a struct, and
26552672 // these extra requirements are basically like where
26562673 // 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) => {
26582677 ( def_id, self . prove_closure_bounds ( tcx, def_id. expect_local ( ) , args, location) )
26592678 }
26602679
@@ -2697,10 +2716,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26972716 let typeck_root_args = ty:: GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
26982717
26992718 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+ }
27022728 }
2703- DefKind :: Closure => args. as_closure ( ) . parent_args ( ) ,
27042729 DefKind :: InlineConst => args. as_inline_const ( ) . parent_args ( ) ,
27052730 other => bug ! ( "unexpected item {:?}" , other) ,
27062731 } ;
0 commit comments