{"record":{"id":"8c2c9793004e86d5","repo":"rust-lang/rust","slug":"async-gen-closures-not-supported-yet","errorCode":null,"errorMessage":"`async gen` closures not supported yet","messagePattern":"`async gen` closures not supported yet","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_hir_typeck/src/closure.rs","lineNumber":197,"sourceCode":"                (\n                    Ty::new_coroutine(tcx, expr_def_id.to_def_id(), coroutine_args.args),\n                    Some(CoroutineTypes { resume_ty, yield_ty }),\n                )\n            }\n            hir::ClosureKind::CoroutineClosure(kind) => {\n                let (bound_return_ty, bound_yield_ty) = match kind {\n                    hir::CoroutineDesugaring::Gen => {\n                        // `iter!` closures always return unit and yield the `Iterator::Item` type\n                        // that we have to infer.\n                        (tcx.types.unit, self.infcx.next_ty_var(expr_span))\n                    }\n                    hir::CoroutineDesugaring::Async => {\n                        // async closures always return the type ascribed after the `->` (if present),\n                        // and yield `()`.\n                        (bound_sig.skip_binder().output(), tcx.types.unit)\n                    }\n                    hir::CoroutineDesugaring::AsyncGen => {\n                        unimplemented!(\"`async gen` closures not supported yet\")\n                    }\n                };\n                // Compute all of the variables that will be used to populate the coroutine.\n                let resume_ty = self.next_ty_var(expr_span);\n\n                let closure_kind_ty = match expected_kind {\n                    Some(kind) => Ty::from_closure_kind(tcx, kind),\n\n                    // Create a type variable (for now) to represent the closure kind.\n                    // It will be unified during the upvar inference phase (`upvar.rs`)\n                    None => self.next_ty_var(expr_span),\n                };\n\n                let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span);\n                let closure_args = ty::CoroutineClosureArgs::new(\n                    tcx,\n                    ty::CoroutineClosureArgsParts {\n                        parent_args,","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_hir_typeck/src/closure.rs#L179-L215","documentation":"An `unimplemented!(\"\\`async gen\\` closures not supported yet\")` ICE in `rustc_hir_typeck`'s closure type-checker. The `CoroutineClosure` desugaring handles `Gen` (gen closures) and `Async` (async closures), but the `AsyncGen` combination (async-gen closures) is recognized but not yet implemented and panics at closure.rs:197.","triggerScenarios":"Writing a closure that combines async and gen desugaring (an `async gen` closure) — e.g. an `async || { yield ... }` form — on a nightly toolchain where the coroutine-closure syntax is parsed but `AsyncGen` lowering is unfinished.","commonSituations":"Experimenting with the newest coroutine-closure features (`gen` + `async` combined) on nightly before the implementation lands. The parser accepts it; the type-checker does not.","solutions":["Do not combine `async` and `gen` in the same closure; use a plain `async` block or a `gen` block separately.","Express the pattern as an `async fn` returning a `gen` block (or vice-versa) instead of a single async-gen closure.","Wait for / upgrade to a nightly where `AsyncGen` closures are implemented."],"exampleFix":"// before (async gen closure -> ICE)\nlet c = async || { yield 1; };\n\n// after — separate async and gen\nasync fn f() {\n    let _g = gen { yield 1; };\n}","handlingStrategy":"validation","validationCode":"# Detect async+gen closure combinations\nrg -nE 'async \\|\\|.*yield|gen move \\|\\|.*await' src/  # review matches","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not combine `async` and `gen` in one closure.","Express async-over-gen as separate `async fn` + `gen` block.","Track nightly support for `AsyncGen` closures before adopting."],"tags":["rustc","hir-typeck","closure","async","gen","coroutine","nightly","ice","compiler-internal","unfinished-feature"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}