{"id":"431833db30360015","repo":"rust-lang/rust","slug":"asynciterator-is-not-const","errorCode":null,"errorMessage":"AsyncIterator is not const","messagePattern":"AsyncIterator is not const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":399,"sourceCode":"    fn consider_builtin_iterator_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution))\n    }\n\n    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>,","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L381-L417","documentation":"Internal `unreachable!` panic in the next-gen trait solver's const-effect candidate assembly for the built-in `AsyncIterator` trait (`core::async_iter::AsyncIterator`). The method `consider_builtin_async_iterator_candidate` exists only to satisfy the `assembly::GoalKind` interface; `AsyncIterator` is explicitly non-const, so execution reaching here is a solver routing bug. The compiler ICEs instead of emitting a diagnostic.","triggerScenarios":"The solver attempts to compute a `HostEffectPredicate` goal for the `AsyncIterator` lang item — i.e. a bound `T: const AsyncIterator` / `T: ~const AsyncIterator`, or an async-generator type forced into const evaluation through generic constraints or `#[const_trait]` propagation.","commonSituations":"Mixing `async`/`AsyncIterator` with nightly `const_trait_impl` experiments; aliasing or projecting over an async iterator inside a `const fn`; enabling `-Znext-solver` on async-heavy code; nightly toolchain regression after the effect-goal routing was widened to cover more built-in traits.","solutions":["Remove any `const`/`~const` bound on `AsyncIterator`; async iteration cannot run in const context.","Confirm the goal isn't synthesized indirectly (e.g. via a `#[const_trait]` trait whose supertrait list includes `AsyncIterator`).","Reproduce with `-Znext-solver=no` / classic solver to verify it is a next-solver-only ICE and report upstream with the reproducer.","Track the rust nightly where it appeared and bisect — async-trait const routing changes frequently."],"exampleFix":"// before\nconst fn drive<T: const AsyncIterator>(_: T) {}\n\n// after\nfn drive<T: AsyncIterator>(_: T) {}","handlingStrategy":"validation","validationCode":"// build.rs: reject const bounds on AsyncIterator before the solver panics\nfn main() {\n    let src = std::fs::read_to_string(\"src/lib.rs\").unwrap_or_default();\n    for banned in [\"~const AsyncIterator\", \"const AsyncIterator\", \"async gen\"] {\n        assert!(!src.contains(banned), \"rejected: {banned} — AsyncIterator needs a runtime executor and is not const\");\n    }\n    println!(\"cargo:rerun-if-changed=src/lib.rs\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["AsyncIterator requires a runtime executor (poll/wake) and cannot exist in const contexts — never combine async-gen/AsyncIterator with `const fn` or `~const` bounds.","Do not generic-over `AsyncIterator` in code reachable from const evaluation.","Poll async iterators only inside a runtime (`tokio`/`async-std`), never from a const or static initializer.","A clean compile error here is expected; a panic/ICE means the solver routed to the const candidate unexpectedly — minimize (report)."],"tags":["rustc","trait-solver","const-traits","ice","asynciterator","async"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}