rust-lang / rust-lang/rust

GCA: error: could not evaluate constant pattern

Open
#162,679 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_args F-min_generic_const_args needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![allow(incomplete_features)]
#![feature(
    generic_const_args,
    min_generic_const_args,
)]

use core::marker::PhantomData;

pub struct S<A>{
    n: usize,
    a: PhantomData<A>,
}

impl<A> S<A> {
    const A: usize = 1;
    const B: usize = 2;

    pub fn foo(self) {
        match self.n {
            Self::A => {}
            Self::B => {}
            _ => {
                unreachable!()
            }
        }
    }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=8a7c9a0e0ae498199f58debc4dd8cfa3

I expected to see this happen:

Compiles successfully

Instead, this happened:

Fails on latest nightly (worked on older versions) with this:

error: could not evaluate constant pattern
  --> src/lib.rs:20:13
   |
14 | impl<A> S<A> {
   | ------------
15 |     const A: usize = 1;
   |     -------------- constant defined here
...
20 |             Self::A => {}
   |             ^^^^^^^ could not evaluate constant

error: could not evaluate constant pattern
  --> src/lib.rs:21:13
   |
14 | impl<A> S<A> {
   | ------------
15 |     const A: usize = 1;
16 |     const B: usize = 2;
   |     -------------- constant defined here
...
21 |             Self::B => {}
   |             ^^^^^^^ could not evaluate constant

Removing generic_const_args or A generic fixes the issue.

Meta

rustc --version --verbose:

rustc 1.100.0-nightly (0fc141305 2026-09-11)
binary: rustc
commit-hash: 0fc141305da7a8a222f65aef1f1acc739c46282b
commit-date: 2026-09-11
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

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

Start by reproducing the failure in src/lib.rs with the provided nightly version and compare it with the cases that remove generic_const_args or the A generic. Trace constant-pattern evaluation for associated constants in the generic impl; done means the reproduction compiles while the relevant regression coverage passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.