Skip to content

generic_const_args: fix unreachable - #162937

Open
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:gca-fix-unreachable
Open

khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:gca-fix-unreachable

Conversation

@khyperia

Copy link
Copy Markdown
Member

I'm really dumb, missed something obvious, and wasn't any test in the test suite to catch it.

Fixes #162923

Introduced in #162760

r? @BoxyUwU or @matthiaskrgr if you'd like

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

rustbot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

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

@khyperia

khyperia commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

wait no I haven't had my coffee yet what am I doing, this isn't the right fix, one moment... (I mean, it worked, but, yeah, actual fix pushed now)

if tcx.features().generic_const_args()
|| matches!(def_kind, DefKind::Const | DefKind::AssocConst)
&& tcx.is_direct_const(def_id)
if matches!(def_kind, DefKind::Const | DefKind::AssocConst)

@BoxyUwU BoxyUwU Sep 18, 2026

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.

haha when I was reviewing that PR I thought about how I hate precedence on these things and can never tell where the parens go 😆

View changes since the review

@BoxyUwU

BoxyUwU commented Sep 18, 2026

Copy link
Copy Markdown
Member

what does the THIR look like for this test, where does a NamedConst come from with a defid of an anon 🤔

@khyperia

khyperia commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

what does the THIR look like for this test, where does a NamedConst come from with a defid of an anon 🤔

comes from here

let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None };

for reference this is what the code looks like:

enum T<const N: u8 = { T::<0>::B as u8 }> {
    A = 2,
    B,
}

the anon const for the default in enum T<const N: u8 = { this one here }> is called T::{constant#0}. the anon const for the A = { this one here }, is called T::A::{constant#0}. lowering a reference to T::<0>::B takes the discr_did (T::A::{constant#0}) and adds discr_offset (1) to it to get T::<0>::B. this THIR expr is then used, casted to u8, and that's the body of the anon const of the default generic param.

T::{constant#0} = (T::A::{constant#0} + 1) as u8;

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.

[ICE]: internal error: entered unreachable code

3 participants