{"record":{"id":"9bebdd32fd83deff","repo":"rust-lang/rust","slug":"coroutine-lowered-from-async-fn-should-be-in-fn","errorCode":null,"errorMessage":"coroutine lowered from async fn should be in fn","messagePattern":"coroutine lowered from async fn should be in fn","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_borrowck/src/diagnostics/region_name.rs","lineNumber":841,"sourceCode":"                    )) => \" of async block\",\n\n                    hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(\n                        hir::CoroutineDesugaring::Async,\n                        hir::CoroutineSource::Closure,\n                    ))\n                    | hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async) => {\n                        \" of async closure\"\n                    }\n\n                    hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(\n                        hir::CoroutineDesugaring::Async,\n                        hir::CoroutineSource::Fn,\n                    )) => {\n                        let parent_item =\n                            tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id);\n                        let output = &parent_item\n                            .fn_decl()\n                            .expect(\"coroutine lowered from async fn should be in fn\")\n                            .output;\n                        span = output.span();\n                        if let hir::FnRetTy::Return(ret) = output {\n                            hir_ty = Some(self.get_future_inner_return_ty(ret));\n                        }\n                        \" of async function\"\n                    }\n\n                    hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(\n                        hir::CoroutineDesugaring::Gen,\n                        hir::CoroutineSource::Block,\n                    )) => \" of gen block\",\n\n                    hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(\n                        hir::CoroutineDesugaring::Gen,\n                        hir::CoroutineSource::Closure,\n                    ))\n                    | hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Gen) => {","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_borrowck/src/diagnostics/region_name.rs#L823-L859","documentation":"region_name.rs:841: when naming a region for an async-fn coroutine with CoroutineSource::Fn, the diagnostic looks up the parent item and calls parent_item.fn_decl().expect(\"coroutine lowered from async fn should be in fn\"). The invariant: a coroutine desugared from an `async fn` is always nested inside an fn item, so the parent must have a fn_decl.","triggerScenarios":"Region-naming for a borrowck error inside an async fn where the parent item is not an fn (has no fn_decl), an inconsistency in coroutine lowering or HIR parent tracking.","commonSituations":"A borrowck diagnostic ICE triggered by lifetime errors inside async fn on a nightly with a coroutine-lowering regression.","solutions":["File a rustc ICE with the minimized async fn lifetime error.","Restructure the async fn (move the problematic borrow out, name the lifetime explicitly) so the region-naming heuristic is not reached.","Bisect across nightlies with cargo bisect-rustc.","Try the equivalent non-async code to confirm the async-specific lowering path."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat as a borrowck diagnostic ICE; report with the minimized async-fn lifetime error.","Name lifetimes explicitly and move problematic borrows out of the async fn to avoid region-naming heuristics.","Bisect with cargo bisect-rustc and compare stable vs nightly.","Pin to a known-good nightly for async-heavy code."],"tags":["rust","borrowck","async","coroutine","ice"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}