{"id":"d59f02b2bc243e47","repo":"rust-lang/rust","slug":"coroutine-is-not-const","errorCode":null,"errorMessage":"Coroutine is not const","messagePattern":"Coroutine is not const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":406,"sourceCode":"    fn consider_builtin_fused_iterator_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"FusedIterator is not const\")\n    }\n\n    fn consider_builtin_async_iterator_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"AsyncIterator is not const\")\n    }\n\n    fn consider_builtin_coroutine_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"Coroutine is not const\")\n    }\n\n    fn consider_builtin_discriminant_kind_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"DiscriminantKind is not const\")\n    }\n\n    fn consider_builtin_destruct_candidate(\n        ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        let cx = ecx.cx();\n\n        let self_ty = goal.predicate.self_ty();\n        let const_conditions = structural_traits::const_conditions_for_destruct(cx, self_ty)?;\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L388-L424","documentation":"Internal `unreachable!` in the next-gen trait solver's const-effect assembly for the built-in `Coroutine` trait (`core::ops::Coroutine`). `consider_builtin_coroutine_candidate` is a stub because coroutines are not const-evaluable; reaching it means a `T: const Coroutine` host-effect goal was routed to built-in candidate assembly. The result is an ICE, not a graceful error.","triggerScenarios":"A host-effect goal resolves to the `Coroutine` lang item: a bound like `T: const Coroutine`, `T: ~const Coroutine`, or a coroutine/closure type being required to satisfy a const coroutine bound inside `const fn` or `#[const_trait]` code. Also reachable through opaque-type projection that hides a coroutine behind a const bound.","commonSituations":"Using nightly `coroutines`/`gen` feature together with `const_trait_impl`; writing `const fn` that generic-dispatches over a coroutine; `-Znext-solver` enabled on code with `yield`/`async gen` blocks; toolchain regression after coroutine effect-goal routing was added.","solutions":["Drop the `const`/`~const Coroutine` bound — coroutines have no const impl.","Check that no `#[const_trait]` trait lists `Coroutine` as a supertrait, which would synthesize the bound implicitly.","Bisect nightlies and report the ICE upstream with a minimal reproducer using `-Znext-solver`.","Retry with the classic solver to confirm the panic is isolated to the next solver's effect-goal path."],"exampleFix":"// before\nconst fn step<G: const Coroutine>(_: G) {}\n\n// after\nfn step<G: Coroutine>(_: G) {}","handlingStrategy":"validation","validationCode":"// build.rs: reject const usage of coroutines (state machines)\nfn main() {\n    let src = std::fs::read_to_string(\"src/lib.rs\").unwrap_or_default();\n    for banned in [\"~const Coroutine\", \"const Coroutine\", \"std::ops::Coroutine\"] {\n        assert!(!src.contains(banned), \"rejected: {banned} — Coroutine is a runtime state machine, not const\");\n    }\n    println!(\"cargo:rerun-if-changed=src/lib.rs\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coroutines are resume-able state machines needing storage across suspensions; they cannot be const — keep `|...| yield ...` / `resume()` out of `const fn`.","Do not put `~const Coroutine` bounds on generic const code.","Replace coroutine logic in const contexts with plain pure functions and explicit state structs.","If the panic appears without an explicit coroutine bound, it is a solver routing bug — reduce the reproducer and report upstream."],"tags":["rustc","trait-solver","const-traits","ice","coroutine"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}