rust-lang / rust-lang/rust

Next-gen Trait Solver does not implement Generic Const Expressions

Open
#129,766 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-generics C-bug F-generic_const_exprs P-low T-compiler T-types WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I was fluffing around with different generic stuff and ended up enabling the Next-gen solver, where I realized that it looked like Generic Const Expressions just don't work at all.

This code seems to work fine with the default trait solver, but when you enable the -Znext-solver flag, it throws a normalization error.

#![feature(generic_const_exprs)]
pub struct Vec<T, const N: usize>
where
    [T; N * N]: Sized,
{
    packed: [T; N * N],
}

I understand this is all very unstable stuff, but thought it was still probably slightly unintended behavior at the least.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (100fde524 2024-08-28)
binary: rustc
commit-hash: 100fde5246bf56f22fb5cc85374dd841296fce0e
commit-date: 2024-08-28
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
Backtrace

error[E0284]: type annotations needed: cannot normalize `Vec<T, N>::packed::{constant#0}`
 --> src/main.rs:6:13
  |
6 |     packed: [T; N * N],
  |             ^^^^^^^^^^ cannot normalize `Vec<T, N>::packed::{constant#0}`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the generic-const-expressions snippet in src/main.rs, first with the default solver and then with -Znext-solver. Read the compiler's trait-solver and normalization entry points to determine where the expression fails; done means the snippet no longer produces the reported normalization error under the next-generation solver.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.