{"id":"1cc1c4e3383fd274","repo":"rust-lang/rust","slug":"fusediterator-is-not-const","errorCode":null,"errorMessage":"FusedIterator is not const","messagePattern":"FusedIterator is not const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":392,"sourceCode":"    fn consider_builtin_future_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"Future is not const\")\n    }\n\n    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>,","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L374-L410","documentation":"This is an internal compiler panic (`unreachable!`) inside rustc's next-generation trait solver, in the `HostEffectPredicate` (const-trait) candidate assembly for the built-in `FusedIterator` trait (`core::iter::FusedIterator`). The solver requires every `assembly::GoalKind` method to exist for completeness, but `FusedIterator` has no `const` implementation, so reaching this branch means the solver mistakenly routed a `T: const FusedIterator` host-effect goal into built-in candidate assembly. It is an ICE: compilation aborts rather than emitting a user-facing diagnostic.","triggerScenarios":"Fired when the const trait solver evaluates a host-effect (constness) goal whose trait def-id resolves to the `FusedIterator` lang item, e.g. a bound like `T: const FusedIterator` or `T: ~const FusedIterator` inside a `const fn`/`#[const_trait]` context. Also reachable if a custom impl or generic constraint indirectly forces the solver to probe a const candidate for `FusedIterator`.","commonSituations":"Experimenting with nightly `const_trait_impl` and `~const` bounds on iterator types; writing `const fn` generic over an iterator; upgrading the nightly toolchain so that code previously rejected now reaches the next solver's effect-goal path; enabling `-Znext-solver` on code that uses iterator combinators in const context.","solutions":["Remove the `const`/`~const` bound on `FusedIterator` — it is not a const trait and never produces a const impl.","If you did not write such a bound, the routing is a compiler bug: file an ICE against rustc with the minimal reproducer and the `-Znext-solver` / edition flags used.","Bisect with a recent nightly; many of these unreachable effect-goal branches are tightened between versions.","Temporarily fall back to the classic solver (remove `-Znext-solver`) to confirm the panic is next-solver-specific before reporting."],"exampleFix":"// before\nconst fn last<T: const FusedIterator>(mut it: T) -> Option<T::Item> { it.next_back() }\n\n// after — FusedIterator is not const; drop the const bound and compute at runtime\nfn last<T: FusedIterator>(mut it: T) -> Option<T::Item> { it.next_back() }","handlingStrategy":"validation","validationCode":"// build.rs or CI step: fail BEFORE rustc ICEs on `const FusedIterator`\nfn main() {\n    let src = std::fs::read_to_string(\"src/lib.rs\").unwrap_or_default();\n    for banned in [\"~const FusedIterator\", \"const FusedIterator\", \"T: const Iterator\"] {\n        assert!(!src.contains(banned), \"rejected const bound: {banned} (FusedIterator has no const impl)\");\n    }\n    println!(\"cargo:rerun-if-changed=src/lib.rs\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write `~const FusedIterator` / `T: const FusedIterator` bounds; the trait has no const candidate by design (effect_goals.rs:392).","Keep iterator consumption (`for`, `.map`, `.fuse()`) out of `const fn` and `static` initializers; move it to runtime.","In const code, iterate with explicit indexing over fixed-size arrays instead of generic iterator traits.","If you hit this as a bare ICE with no obvious const bound in your source, file a rustc issue: reaching the builtin candidate is a solver routing bug."],"tags":["rustc","trait-solver","const-traits","ice","fusediterator"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}