@@ -204,14 +204,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204204 )
205205 }
206206 hir:: ClosureKind :: CoroutineClosure ( kind) => {
207- // async closures always return the type ascribed after the `->` (if present),
208- // and yield `()`.
209207 let ( bound_return_ty, bound_yield_ty) = match kind {
208+ hir:: CoroutineDesugaring :: Gen => {
209+ // `iter!` closures always return unit and yield the `Iterator::Item` type
210+ // that we have to infer.
211+ ( tcx. types . unit , self . infcx . next_ty_var ( expr_span) )
212+ }
210213 hir:: CoroutineDesugaring :: Async => {
214+ // async closures always return the type ascribed after the `->` (if present),
215+ // and yield `()`.
211216 ( bound_sig. skip_binder ( ) . output ( ) , tcx. types . unit )
212217 }
213- hir:: CoroutineDesugaring :: Gen | hir :: CoroutineDesugaring :: AsyncGen => {
214- todo ! ( "`gen` and ` async gen` closures not supported yet" )
218+ hir:: CoroutineDesugaring :: AsyncGen => {
219+ todo ! ( "`async gen` closures not supported yet" )
215220 }
216221 } ;
217222 // Compute all of the variables that will be used to populate the coroutine.
@@ -465,7 +470,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
465470
466471 if let Some ( trait_def_id) = trait_def_id {
467472 let found_kind = match closure_kind {
468- hir:: ClosureKind :: Closure => self . tcx . fn_trait_kind_from_def_id ( trait_def_id) ,
473+ hir:: ClosureKind :: Closure
474+ // FIXME(iter_macro): Someday we'll probably want iterator closures instead of
475+ // just using Fn* for iterators.
476+ | hir:: ClosureKind :: CoroutineClosure ( hir:: CoroutineDesugaring :: Gen ) => {
477+ self . tcx . fn_trait_kind_from_def_id ( trait_def_id)
478+ }
469479 hir:: ClosureKind :: CoroutineClosure ( hir:: CoroutineDesugaring :: Async ) => self
470480 . tcx
471481 . async_fn_trait_kind_from_def_id ( trait_def_id)
0 commit comments