@@ -105,59 +105,76 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
105105 span : self . tcx . def_span ( expr_def_id) ,
106106 } ) ;
107107
108- if let Some ( CoroutineTypes { resume_ty, yield_ty, interior } ) = coroutine_types {
109- let coroutine_args = ty:: CoroutineArgs :: new (
110- self . tcx ,
111- ty:: CoroutineArgsParts {
112- parent_args,
113- resume_ty,
114- yield_ty,
115- return_ty : liberated_sig. output ( ) ,
116- witness : interior,
117- tupled_upvars_ty,
118- } ,
119- ) ;
120-
121- return Ty :: new_coroutine ( self . tcx , expr_def_id. to_def_id ( ) , coroutine_args. args ) ;
122- }
123-
124- // Tuple up the arguments and insert the resulting function type into
125- // the `closures` table.
126- let sig = bound_sig. map_bound ( |sig| {
127- self . tcx . mk_fn_sig (
128- [ Ty :: new_tup ( self . tcx , sig. inputs ( ) ) ] ,
129- sig. output ( ) ,
130- sig. c_variadic ,
131- sig. unsafety ,
132- sig. abi ,
133- )
134- } ) ;
135-
136- debug ! ( ?sig, ?opt_kind) ;
137-
138- let closure_kind_ty = match opt_kind {
139- Some ( kind) => Ty :: from_closure_kind ( self . tcx , kind) ,
108+ match closure. kind {
109+ hir:: ClosureKind :: Closure => {
110+ assert_eq ! ( coroutine_types, None ) ;
111+ // Tuple up the arguments and insert the resulting function type into
112+ // the `closures` table.
113+ let sig = bound_sig. map_bound ( |sig| {
114+ self . tcx . mk_fn_sig (
115+ [ Ty :: new_tup ( self . tcx , sig. inputs ( ) ) ] ,
116+ sig. output ( ) ,
117+ sig. c_variadic ,
118+ sig. unsafety ,
119+ sig. abi ,
120+ )
121+ } ) ;
140122
141- // Create a type variable (for now) to represent the closure kind.
142- // It will be unified during the upvar inference phase (`upvar.rs`)
143- None => self . next_root_ty_var ( TypeVariableOrigin {
144- // FIXME(eddyb) distinguish closure kind inference variables from the rest.
145- kind : TypeVariableOriginKind :: ClosureSynthetic ,
146- span : expr_span,
147- } ) ,
148- } ;
123+ debug ! ( ?sig, ?opt_kind) ;
124+
125+ let closure_kind_ty = match opt_kind {
126+ Some ( kind) => Ty :: from_closure_kind ( self . tcx , kind) ,
127+
128+ // Create a type variable (for now) to represent the closure kind.
129+ // It will be unified during the upvar inference phase (`upvar.rs`)
130+ None => self . next_root_ty_var ( TypeVariableOrigin {
131+ // FIXME(eddyb) distinguish closure kind inference variables from the rest.
132+ kind : TypeVariableOriginKind :: ClosureSynthetic ,
133+ span : expr_span,
134+ } ) ,
135+ } ;
136+
137+ let closure_args = ty:: ClosureArgs :: new (
138+ self . tcx ,
139+ ty:: ClosureArgsParts {
140+ parent_args,
141+ closure_kind_ty,
142+ closure_sig_as_fn_ptr_ty : Ty :: new_fn_ptr ( self . tcx , sig) ,
143+ tupled_upvars_ty,
144+ } ,
145+ ) ;
149146
150- let closure_args = ty:: ClosureArgs :: new (
151- self . tcx ,
152- ty:: ClosureArgsParts {
153- parent_args,
154- closure_kind_ty,
155- closure_sig_as_fn_ptr_ty : Ty :: new_fn_ptr ( self . tcx , sig) ,
156- tupled_upvars_ty,
157- } ,
158- ) ;
147+ Ty :: new_closure ( self . tcx , expr_def_id. to_def_id ( ) , closure_args. args )
148+ }
149+ hir:: ClosureKind :: Coroutine ( _) => {
150+ let Some ( CoroutineTypes { resume_ty, yield_ty } ) = coroutine_types else {
151+ bug ! ( "expected coroutine to have yield/resume types" ) ;
152+ } ;
153+ let interior = fcx. next_ty_var ( TypeVariableOrigin {
154+ kind : TypeVariableOriginKind :: MiscVariable ,
155+ span : body. value . span ,
156+ } ) ;
157+ fcx. deferred_coroutine_interiors . borrow_mut ( ) . push ( (
158+ expr_def_id,
159+ body. id ( ) ,
160+ interior,
161+ ) ) ;
162+
163+ let coroutine_args = ty:: CoroutineArgs :: new (
164+ self . tcx ,
165+ ty:: CoroutineArgsParts {
166+ parent_args,
167+ resume_ty,
168+ yield_ty,
169+ return_ty : liberated_sig. output ( ) ,
170+ witness : interior,
171+ tupled_upvars_ty,
172+ } ,
173+ ) ;
159174
160- Ty :: new_closure ( self . tcx , expr_def_id. to_def_id ( ) , closure_args. args )
175+ Ty :: new_coroutine ( self . tcx , expr_def_id. to_def_id ( ) , coroutine_args. args )
176+ }
177+ }
161178 }
162179
163180 /// Given the expected type, figures out what it can about this closure we
0 commit comments