rust-lang/rust · error

AsyncFn* are not yet const

Error message

AsyncFn* are not yet const

What it means

An `unimplemented!("AsyncFn* are not yet const")` ICE in the next trait solver (`consider_builtin_async_fn_trait_candidates`). When the new solver must build a candidate proving an async-callable type (async closure / async fn / async fn pointer) satisfies a const `AsyncFn`/`AsyncFnMut`/`AsyncFnOnce` obligation, the candidate is unimplemented and panics at effect_goals.rs:350.

Solutions

  1. Do not enable `-Znext-solver` when using const async-closure patterns.
  2. Move the async-closure call out of const context (use it at runtime).
  3. Track upstream const-`AsyncFn*` support in the next solver.

Example fix

// before (next solver + const async closure call -> ICE)
const fn run(f: async || -> i32) -> ... { f() }
// compiled with: -Znext-solver

// after — runtime call, no -Znext-solver
fn run(f: impl async Fn() -> i32) -> impl Future<Output = i32> { async { f().await } }
Defensive patterns

Strategy: fallback

Validate before calling

# Detect next-solver + const async closure calls
if [[ "${RUSTFLAGS:-}" == *next-solver* ]]; then
  rg -nE 'async \|\||const fn .*AsyncFn' src/ && echo "avoid: const AsyncFn* unsupported in the next solver"
fi

Prevention

When it happens

Trigger: Enabling `-Znext-solver` and requiring const `AsyncFn*` — e.g. calling an async closure in a `const` context that the new solver must discharge.

Common situations: Nightly + `-Znext-solver` + experimental const async-closure usage. Not reachable on stable.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/83dad5ee68fe2893. Report an issue: GitHub.

Appendix: source

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

        ))
        .to_host_effect_clause(cx, goal.predicate.constness);

        Self::probe_and_consider_implied_clause(
            ecx,
            CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
            goal,
            pred,
            requirements,
        )
        .map_err(Into::into)
    }

    fn consider_builtin_async_fn_trait_candidates(
        _ecx: &mut EvalCtxt<'_, D>,
        _goal: Goal<I, Self>,
        _kind: rustc_type_ir::ClosureKind,
    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
        unimplemented!("AsyncFn* are not yet const")
    }

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

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

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

View on GitHub (pinned to 7088e4b63a)