Skip to content

Handle primitive constants in const arguments for MGCA#158590

Open
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158506-mgca-primitive-consts
Open

Handle primitive constants in const arguments for MGCA#158590
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158506-mgca-primitive-consts

Conversation

@chenyukang

@chenyukang chenyukang commented Jun 29, 2026

Copy link
Copy Markdown
Member

MGCA direct const arg lowering bypasses expression primitive fallback for paths like u8::MAX, so they are treated as ambiguous type-level associated constants instead of primitive associated constants.

Fixes #158506

r? @BoxyUwU

link #149136

@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 Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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

@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

lol that's a really funny bug 🤔 this fix feels slightly off to me though, i would generally like for the distinction between anon const and direct repr to be quite obvious/simple and this complicates that with a special case about the exact way the path looks 🤔

it is weird to me that we fail to resolve the associated constant in the first place (even with inherent_associated_types enabled!). do you have a sense of why HIR ty lowering doesn't resolve the associated constant? if there's some special casing in normal lookup of associated constants in HIR typeck that isn't present in HIR ty lowering then we probably want to replicate it in HIR ty lowering so that we do succeed in resolving the associated constant when it's directly represented

thx for looking into this

@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 Jul 8, 2026
@chenyukang

Copy link
Copy Markdown
Member Author

lol that's a really funny bug 🤔 this fix feels slightly off to me though, i would generally like for the distinction between anon const and direct repr to be quite obvious/simple and this complicates that with a special case about the exact way the path looks 🤔

it is weird to me that we fail to resolve the associated constant in the first place (even with inherent_associated_types enabled!). do you have a sense of why HIR ty lowering doesn't resolve the associated constant? if there's some special casing in normal lookup of associated constants in HIR typeck that isn't present in HIR ty lowering then we probably want to replicate it in HIR ty lowering so that we do succeed in resolving the associated constant when it's directly represented

thx for looking into this

@rustbot author

Normal expression lookup resolves u8::MAX through method probe in Mode::Path,then considers associated values and includes candidates from tcx.incoherent_impls(...) for primitive self types.

HIR ty lowering direct const path missing this part, here we only call probe_inherent_assoc_item for ADT type

if let Some(alias_term) = self.probe_inherent_assoc_item(

so primitive type fail through to resolve_type_relative_path.

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #159046) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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.

min_generic_const_args makes {u,i}*::{MIN, MAX} ambiguous

3 participants