@@ -97,6 +97,10 @@ pub enum DefiningTy<'tcx> {
97
97
/// `ClosureArgs::coroutine_return_ty`.
98
98
Coroutine ( DefId , GenericArgsRef < ' tcx > ) ,
99
99
100
+ /// The MIR is a special kind of closure that returns coroutines.
101
+ /// TODO: describe how to make the sig...
102
+ CoroutineClosure ( DefId , GenericArgsRef < ' tcx > ) ,
103
+
100
104
/// The MIR is a fn item with the given `DefId` and args. The signature
101
105
/// of the function can be bound then with the `fn_sig` query.
102
106
FnDef ( DefId , GenericArgsRef < ' tcx > ) ,
@@ -119,6 +123,7 @@ impl<'tcx> DefiningTy<'tcx> {
119
123
pub fn upvar_tys ( self ) -> & ' tcx ty:: List < Ty < ' tcx > > {
120
124
match self {
121
125
DefiningTy :: Closure ( _, args) => args. as_closure ( ) . upvar_tys ( ) ,
126
+ DefiningTy :: CoroutineClosure ( _, args) => args. as_coroutine_closure ( ) . upvar_tys ( ) ,
122
127
DefiningTy :: Coroutine ( _, args) => args. as_coroutine ( ) . upvar_tys ( ) ,
123
128
DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) | DefiningTy :: InlineConst ( ..) => {
124
129
ty:: List :: empty ( )
@@ -131,7 +136,9 @@ impl<'tcx> DefiningTy<'tcx> {
131
136
/// user's code.
132
137
pub fn implicit_inputs ( self ) -> usize {
133
138
match self {
134
- DefiningTy :: Closure ( ..) | DefiningTy :: Coroutine ( ..) => 1 ,
139
+ DefiningTy :: Closure ( ..)
140
+ | DefiningTy :: CoroutineClosure ( ..)
141
+ | DefiningTy :: Coroutine ( ..) => 1 ,
135
142
DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) | DefiningTy :: InlineConst ( ..) => 0 ,
136
143
}
137
144
}
@@ -147,6 +154,7 @@ impl<'tcx> DefiningTy<'tcx> {
147
154
pub fn def_id ( & self ) -> DefId {
148
155
match * self {
149
156
DefiningTy :: Closure ( def_id, ..)
157
+ | DefiningTy :: CoroutineClosure ( def_id, ..)
150
158
| DefiningTy :: Coroutine ( def_id, ..)
151
159
| DefiningTy :: FnDef ( def_id, ..)
152
160
| DefiningTy :: Const ( def_id, ..)
@@ -355,6 +363,9 @@ impl<'tcx> UniversalRegions<'tcx> {
355
363
err. note ( format ! ( "late-bound region is {:?}" , self . to_region_vid( r) ) ) ;
356
364
} ) ;
357
365
}
366
+ DefiningTy :: CoroutineClosure ( ..) => {
367
+ todo ! ( )
368
+ }
358
369
DefiningTy :: Coroutine ( def_id, args) => {
359
370
let v = with_no_trimmed_paths ! (
360
371
args[ tcx. generics_of( def_id) . parent_count..]
@@ -568,6 +579,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
568
579
match * defining_ty. kind ( ) {
569
580
ty:: Closure ( def_id, args) => DefiningTy :: Closure ( def_id, args) ,
570
581
ty:: Coroutine ( def_id, args) => DefiningTy :: Coroutine ( def_id, args) ,
582
+ ty:: CoroutineClosure ( def_id, args) => {
583
+ DefiningTy :: CoroutineClosure ( def_id, args)
584
+ }
571
585
ty:: FnDef ( def_id, args) => DefiningTy :: FnDef ( def_id, args) ,
572
586
_ => span_bug ! (
573
587
tcx. def_span( self . mir_def) ,
@@ -623,6 +637,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
623
637
let identity_args = GenericArgs :: identity_for_item ( tcx, typeck_root_def_id) ;
624
638
let fr_args = match defining_ty {
625
639
DefiningTy :: Closure ( _, args)
640
+ | DefiningTy :: CoroutineClosure ( _, args)
626
641
| DefiningTy :: Coroutine ( _, args)
627
642
| DefiningTy :: InlineConst ( _, args) => {
628
643
// In the case of closures, we rely on the fact that
@@ -702,6 +717,47 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
702
717
ty:: Binder :: dummy ( inputs_and_output)
703
718
}
704
719
720
+ DefiningTy :: CoroutineClosure ( def_id, args) => {
721
+ assert_eq ! ( self . mir_def. to_def_id( ) , def_id) ;
722
+ let closure_sig = args. as_coroutine_closure ( ) . coroutine_closure_sig ( ) ;
723
+ let bound_vars = tcx. mk_bound_variable_kinds_from_iter (
724
+ closure_sig
725
+ . bound_vars ( )
726
+ . iter ( )
727
+ . chain ( iter:: once ( ty:: BoundVariableKind :: Region ( ty:: BrEnv ) ) ) ,
728
+ ) ;
729
+ let br = ty:: BoundRegion {
730
+ var : ty:: BoundVar :: from_usize ( bound_vars. len ( ) - 1 ) ,
731
+ kind : ty:: BrEnv ,
732
+ } ;
733
+ let env_region = ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) ;
734
+ let closure_kind = args. as_coroutine_closure ( ) . kind ( ) ;
735
+
736
+ let closure_ty = tcx. closure_env_ty (
737
+ Ty :: new_coroutine_closure ( tcx, def_id, args) ,
738
+ closure_kind,
739
+ env_region,
740
+ ) ;
741
+
742
+ let inputs = closure_sig. skip_binder ( ) . tupled_inputs_ty . tuple_fields ( ) ;
743
+ let output = closure_sig. skip_binder ( ) . to_coroutine_given_kind_and_upvars (
744
+ tcx,
745
+ args. as_coroutine_closure ( ) . parent_args ( ) ,
746
+ tcx. coroutine_for_closure ( def_id) ,
747
+ closure_kind,
748
+ env_region,
749
+ args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) ,
750
+ args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ,
751
+ ) ;
752
+
753
+ ty:: Binder :: bind_with_vars (
754
+ tcx. mk_type_list_from_iter (
755
+ iter:: once ( closure_ty) . chain ( inputs) . chain ( iter:: once ( output) ) ,
756
+ ) ,
757
+ bound_vars,
758
+ )
759
+ }
760
+
705
761
DefiningTy :: FnDef ( def_id, _) => {
706
762
let sig = tcx. fn_sig ( def_id) . instantiate_identity ( ) ;
707
763
let sig = indices. fold_to_region_vids ( tcx, sig) ;
0 commit comments