rust-lang/rust · error

`feature(generic_const_exprs)` is not supported in the new t

Error message

`feature(generic_const_exprs)` is not supported in the new trait solver

What it means

Explicit unimplemented! guard: the unstable feature(generic_const_exprs) (const expressions in generic positions, e.g. `[T; N + 1]`) is not yet supported by the next trait solver. compute_const_arg_has_type_goal bails when it sees a ConstKind::Expr, which is the IR node produced by that feature. Unlike the other panics here, this is an intentional, user-facing limitation rather than a solver invariant.

Source

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

        let ct_ty = match ct.kind() {
            ty::ConstKind::Infer(_) => {
                return self
                    .evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
                    .map_err(Into::into);
            }
            ty::ConstKind::Error(_) => {
                return self
                    .evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
                    .map_err(Into::into);
            }
            ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => {
                alias_const.type_of(self.cx()).skip_norm_wip()
            }
            ty::ConstKind::Alias(ty::IsRigid::No, _) => unimplemented!(
                "non-rigid unevaluated constant for compute_const_arg_has_type_goal: {ct:?}"
            ),
            ty::ConstKind::Expr(_) => unimplemented!(
                "`feature(generic_const_exprs)` is not supported in the new trait solver"
            ),
            ty::ConstKind::Param(_) => {
                unreachable!("`ConstKind::Param` should have been canonicalized to `Placeholder`")
            }
            ty::ConstKind::Bound(_, _) => panic!("escaping bound vars in {:?}", ct),
            ty::ConstKind::Value(cv) => cv.ty(),
            ty::ConstKind::Placeholder(placeholder) => {
                placeholder.find_const_ty_from_env(goal.param_env)
            }
        };

        self.eq(goal.param_env, ct_ty, ty)?;
        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into)
    }
}

#[derive(Debug)]

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Do not combine #![feature(generic_const_exprs)] with -Znext-solver; remove the feature attribute or disable the solver.
  2. Replace generic const expressions with concrete consts or associated consts that do not produce ConstKind::Expr.
  3. Wait for / contribute to the upstream implementation tracking generic_const_exprs in the new solver.
  4. If you must keep the feature, compile the affected crate with the old solver (no -Znext-solver, or -Znext-solver=coherence to limit its scope).

Example fix

// before: generic const expr + next-solver -> ICE
#![feature(generic_const_exprs)]
struct S<const N: usize> { a: [u8; N + 1] } // N + 1 is a ConstKind::Expr

// after: drop the feature and use a plain const parameter
struct S<const N: usize> { a: [u8; N] } // caller passes the full size directly
Defensive patterns

Strategy: validation

Validate before calling

// `feature(generic_const_exprs)` is incompatible with the new trait solver.
// Block the build if both are present.
fn uses_generic_const_exprs(src: &str) -> bool {
    src.contains("#!feature(generic_const_exprs)") || src.contains("#[feature(generic_const_exprs)]")
}
fn next_solver_active() -> bool {
    std::env::var("RUSTFLAGS").unwrap_or_default().contains("next-solver")
}
#[test]
fn no_gce_with_next_solver() {
    let src = std::fs::read_to_string("src/lib.rs").unwrap_or_default();
    assert!(!(uses_generic_const_exprs(&src) && next_solver_active()),
        "generic_const_exprs cannot coexist with -Znext-solver");
}

Try / catch

use std::panic::{catch_unwind, AssertUnwindSafe};
let r = catch_unwind(AssertUnwindSafe(|| cargo_build_with_features(&["generic_const_exprs"])));
if r.is_err() { eprintln!("disable -Znext-solver or remove generic_const_exprs"); }

Prevention

When it happens

Trigger: Triggered when a crate with #![feature(generic_const_exprs)] (or any code path emitting ConstKind::Expr) is compiled with -Znext-solver enabled and a const-arg-has-type goal reaches the Expr arm at compiler/rustc_next_trait_solver/src/solve/mod.rs:269.

Common situations: Users enabling both #![feature(generic_const_exprs)] and the next trait solver in the same compilation. Common when experimenting on nightly with const generics (e.g. generic array sizes expressed as expressions) while also testing -Znext-solver.

Related errors


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