rust-lang/rust · critical

unexpected const kind: {:?}

Error message

unexpected const kind: {:?}

What it means

compute_const_evaluatable_goal only accepts Alias(rigid)/Placeholder/Value/Error/Infer const kinds. Param, Bound, and Expr are all declared unreachable: Param is rewritten to Placeholder during canonicalization, Bound cannot exist without an enclosing binder around the self type, and Expr belongs to the unimplemented generic_const_exprs feature. Reaching this panic means one of those invariants was violated.

Source

Thrown at compiler/rustc_next_trait_solver/src/solve/mod.rs:239

                // error in that case is unnecessary noise. This may change in the future once
                // evaluation failures are allowed to impact selection, e.g. generic const
                // expressions in impl headers or `where`-clauses.

                // FIXME(generic_const_exprs): Implement handling for generic
                // const expressions here.
                if let Some(_normalized) = self.evaluate_const(param_env, alias_const)? {
                    self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
                } else {
                    self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
                }
            }

            // We can freely ICE here as:
            // - `Param` gets replaced with a placeholder during canonicalization
            // - `Bound` cannot exist as we don't have a binder around the self Type
            // - `Expr` is part of `feature(generic_const_exprs)` and is not implemented yet
            ty::ConstKind::Param(_) | ty::ConstKind::Bound(_, _) | ty::ConstKind::Expr(_) => {
                panic!("unexpected const kind: {:?}", ct)
            }
        }
    }

    #[instrument(level = "trace", skip(self), ret)]
    fn compute_const_arg_has_type_goal(
        &mut self,
        goal: Goal<I, (I::Const, I::Ty)>,
    ) -> QueryResultOrRerunNonErased<I> {
        let (ct, ty) = goal.predicate;
        let ct = self.structurally_normalize_const(goal.param_env, ct)?;

        let ct_ty = match ct.kind() {
            ty::ConstKind::Infer(_) => {
                return self
                    .evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
                    .map_err(Into::into);
            }

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Report the ICE with the {:?} const printed by the panic and a minimal repro.
  2. If the panic mentions an Expr const, stop using #![feature(generic_const_exprs)] under -Znext-solver (see error 299).
  3. If it mentions a Param, audit canonicalization to confirm params are rewritten to placeholders before goal evaluation.
  4. Disable -Znext-solver as a workaround.
Defensive patterns

Strategy: type-guard

Validate before calling

// Only a closed set of const kinds reaches the new solver safely. Reject everything else
// at the source before it is handed to rustc.
fn const_kind_allowed(k: &ConstKind) -> bool {
    matches!(k, ConstKind::Param(_) | ConstKind::Value(_) | ConstKind::Error(_))
}

Type guard

enum RigidConst { Value(i128), Param(&'static str) }
impl RigidConst { fn from_kind(k: &ConstKind) -> Option<Self> {
    match k { ConstKind::Value(v) => Some(Self::Value(*v)), ConstKind::Param(p) => Some(Self::Param(p)), _ => None }
}}

Try / catch

use std::panic::{catch_unwind, AssertUnwindSafe};
let c = catch_unwind(AssertUnwindSafe(|| classify_const(kind)));
c.unwrap_or(ConstClassification::Error)

Prevention

When it happens

Trigger: Triggered in compute_const_evaluatable_goal (compiler/rustc_next_trait_solver/src/solve/mod.rs:202) when the const argument's kind is ConstKind::Param (canonicalization skipped), ConstKind::Bound (binder leaked into the self type), or ConstKind::Expr (generic_const_exprs const expression reached evaluation).

Common situations: ICE on const-generic code under -Znext-solver. Param case points to a canonicalization regression; Bound case to a binder-handling bug; Expr case to use of generic_const_exprs, which the new solver does not yet support.

Related errors


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