Skip to content

avoid ICE when generics sneak into a constant pattern#159504

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:generic-in-pat
Open

avoid ICE when generics sneak into a constant pattern#159504
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:generic-in-pat

Conversation

@RalfJung

@RalfJung RalfJung commented Jul 18, 2026

Copy link
Copy Markdown
Member

Since recently, const validation has a has_param check, which means ConstToPat also implicitly has that check. But it seems better to check this again explicitly here rather then rely on an undocumented property of some other component. The new test behaves the same with or without the PR.

I recommend hiding whitespace difference, since rustfmt re-indendet a bunch of stuff.
Fixes #150296
r? @BoxyUwU

@rustbot

rustbot commented Jul 18, 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 Jul 18, 2026
@rustbot

rustbot commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

// become necessary to just use type system normalization for all const patterns
// but that's not yet possible.
let mut thir_pat = if alias_const.kind.is_type_const(self.tcx) {
let const_value = if alias_const.kind.is_type_const(self.tcx) {

@RalfJung RalfJung Jul 18, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems kind of odd to me that we are treating type constants separately here, I would think there should be a uniform code path... but that is pre-existing so 🤷

View changes since the review

@Nadrieril Nadrieril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl LGTM. This looks like technically a breaking change, am I to understand that this used to ICE before so it's fine?

View changes since this review

@RalfJung

Copy link
Copy Markdown
Member Author

I think this PR doesn't change anything at all. If there's a breaking change it already occurred when #156977 landed which made it so that evaluating a constant with generics in its type can never get past validation.

Maybe we should just have that check in the beginning of the query rather than the end, and make it a proper guarantee of our const-eval queries rather than something ad-hoc in const-to-pat? Cc @rust-lang/wg-const-eval

@Nadrieril

Copy link
Copy Markdown
Member

Maybe we should [...] make it a proper guarantee of our const-eval queries

That sounds a lot more principled, yes please

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StructuralPartialEq computation error

4 participants