Skip to content

CTFE const pattern bodies that normalization leaves generic - #166077

Open
lapla-cogito wants to merge 1 commit into
rust-lang:mainfrom
lapla-cogito:issue_162679
Open

lapla-cogito wants to merge 1 commit into
rust-lang:mainfrom
lapla-cogito:issue_162679

Conversation

@lapla-cogito

@lapla-cogito lapla-cogito commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Under gca_const_items, normalization leaves a const pattern as an alias when its generic arguments still mention parameters, even if the body does not use them. Evaluate that remaining body with CTFE so it can be used as a pattern.

Fixes #162679

r? khyperia

@rustbot

rustbot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 16, 2026
@khyperia

Copy link
Copy Markdown
Member

thanks for the PR!

I believe this approach is a little wonky, and is masked a little bit by the fact that after #165070 on main if you replace let const_value = if self.tcx.features().gca_const_items() || alias_const.kind.is_direct_const(self.tcx) { with let const_value = if false {, all tests (including tests/ui/const-generics/mgca/const-pattern-generic-impl.rs) pass. I am unsure if this is the "correct" approach (need to think on it more), but simply nuking the typesystem norm block and always using const_eval_resolve_for_typeck is a simpler version of this PR AFAIK.

Feel free to poke me in the const generics zulip, this is a quite difficult and complex theoretical change that I've been thinking about how to solve for a couple months now!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2026
@rustbot

rustbot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@khyperia

Copy link
Copy Markdown
Member

@bit-aloo mentioned this in zulip:

#![feature(gca_min_const_items)]
#![feature(gca_const_items)]

trait Trait {
    const A: usize;
}

fn f<T: Trait<A = 3>>(n: usize) -> bool {
    match n {
        T::A => true,
        _ => false,
    }
}

unsure, but at the very least, this should be a test that's checked in, its behavior currently isn't tracked

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GCA: error: could not evaluate constant pattern

3 participants