rust-lang / rust-lang/rust

Can't match on associated const on next-solver

Open
#162,331 0 comments 1 reaction 1 assignee View on GitHub

@dianne is already working on this.

Since Sep 10, 2026.

A-const-eval A-patterns C-bug P-medium regression-from-stable-to-nightly T-types WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

This issue was initially reported at https://github.com/mahkoh/linearize/issues/38

I tried this code:

pub trait Trait {
    const N: usize;
}

impl Trait for u8 {
    const N: usize = 0;
}

pub fn f()
where
    u8: Trait,
{
    match 0 {
        <u8 as Trait>::N => {}
        _ => {}
    }
}

This code compiles on beta, and on nightly with -Znext-solver=coherence. However, on nightly without extra arguments (which defaults to -Znext-solver=everywhere), it doesn't compile, with the following error:

error[E0158]: constant pattern cannot depend on generic parameters
  --> src/lib.rs:14:9
   |
 1 | pub trait Trait {
   | ---------------
 2 |     const N: usize;
   |     -------------- constant defined here
...
14 |         <u8 as Trait>::N => {}
   |         ^^^^^^^^^^^^^^^^ `const` depends on a generic parameter

For more information about this error, try `rustc --explain E0158`.
Version it worked on

It most recently worked on:

rustc --version --verbose:

rustc 1.99.0-beta.3 (cbae9b4ca 2026-08-28)
binary: rustc
commit-hash: cbae9b4cae2b108f6a3d18cfe6075714bb739463
commit-date: 2026-08-28
host: aarch64-apple-darwin
release: 1.99.0-beta.3
LLVM version: 23.1.0
Version with regression

rustc --version --verbose:

rustc 1.100.0-nightly (0ed41eb41 2026-09-04)
binary: rustc
commit-hash: 0ed41eb4142dda2df61eb1145a312c1a9d62eb56
commit-date: 2026-09-04
host: aarch64-apple-darwin
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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.