rust-lang/rust · critical

FusedIterator is not const

Error message

FusedIterator is not const

What it means

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.

Source

Thrown at compiler/rustc_next_trait_solver/src/solve/effect_goals.rs:392

    fn consider_builtin_future_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        unreachable!("Future is not const")
    }

    fn consider_builtin_iterator_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution))
    }

    fn consider_builtin_fused_iterator_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        unreachable!("FusedIterator is not const")
    }

    fn consider_builtin_async_iterator_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        unreachable!("AsyncIterator is not const")
    }

    fn consider_builtin_coroutine_candidate(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        unreachable!("Coroutine is not const")
    }

    fn consider_builtin_discriminant_kind_candidate(
        _ecx: &mut EvalCtxt<'_, D>,

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Remove the `const`/`~const` bound on `FusedIterator` — it is not a const trait and never produces a const impl.
  2. 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.
  3. Bisect with a recent nightly; many of these unreachable effect-goal branches are tightened between versions.
  4. Temporarily fall back to the classic solver (remove `-Znext-solver`) to confirm the panic is next-solver-specific before reporting.

Example fix

// before
const fn last<T: const FusedIterator>(mut it: T) -> Option<T::Item> { it.next_back() }

// after — FusedIterator is not const; drop the const bound and compute at runtime
fn last<T: FusedIterator>(mut it: T) -> Option<T::Item> { it.next_back() }
Defensive patterns

Strategy: validation

Validate before calling

// build.rs or CI step: fail BEFORE rustc ICEs on `const FusedIterator`
fn main() {
    let src = std::fs::read_to_string("src/lib.rs").unwrap_or_default();
    for banned in ["~const FusedIterator", "const FusedIterator", "T: const Iterator"] {
        assert!(!src.contains(banned), "rejected const bound: {banned} (FusedIterator has no const impl)");
    }
    println!("cargo:rerun-if-changed=src/lib.rs");
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/1cc1c4e3383fd274.json. Report an issue: GitHub.