Skip to content

Fix ICE in normalizing inherent associated consts with #[type_const]#152000

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
lapla-cogito:ice_151027
Feb 6, 2026
Merged

Fix ICE in normalizing inherent associated consts with #[type_const]#152000
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
lapla-cogito:ice_151027

Conversation

@lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Feb 2, 2026

Fixes #151027
Fixes #138089
Fixes #138226
Fixes #150960

When an inherent associated const is marked with #[type_const], its generics expect args in the format [Self, own_params...], similar to inherent associated types. However, HIR typeck's instantiate_value_path was constructing args in the regular associated const format [impl_params..., own_params...]. This mismatch caused ICEs when the args were later used in contexts expecting the IAC format, such as user type annotations and borrowck's type ascription.

@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 Feb 2, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@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 Feb 2, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2026

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

@nnethercote
Copy link
Contributor

r? @fmease

@rustbot rustbot assigned fmease and unassigned nnethercote Feb 3, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 3, 2026

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

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

If you're interested in fixing this I would recommend reading through #project-const-generics > Inherent associated consts (`IAC`) under `MGCA` as I talk there about what a proper fix for our improper handling of inherent associated consts would be

@BoxyUwU BoxyUwU self-assigned this Feb 4, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

I expect that we'll need to make instantiate_value_path for inherent associated type consts yield proper type-system-compatible args (i.e. [Self, Gat0..N]), as well as the stuff in that thread about making the trait solvers even handle IACs correctly in the first place. Would definitely be a multi-PR kind of thing and I would probably not start with caring about instantiate_value_path

@lapla-cogito
Copy link
Contributor Author

@BoxyUwU Thank you! I'm interested in resolving this ICE issue series, so I reviewed the thread you provided. I have several questions:

  • Has the fix approach suggested in the thread already been implemented in this commit by you?
  • Why do you think the instantiate_value_path modification should be deferred? Are there specific factors, such as yet unresolved issues with trait solver IAC support that depend on it?
  • (This likely depends heavily on the answer above) Should this be closed? If so, I don't think I should make decisions on how to resolve this alone. What would be an appropriate approach?

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

oh apparently yes I did implement a lot of that? cool.. In that case I think the two things necessary now are:

  • Update debug_assert_args_are_compatible to special case IACs not just IATs
  • Make instantiate_value_path/whatever return correctly laid out arguments for type_consts

In which case doing it all in this PR seems totally reasonable :)

@rust-log-analyzer

This comment has been minimized.

@lapla-cogito
Copy link
Contributor Author

I've implemented the necessary measures to suppress the ICE (though proper handling of crashtest cases that no longer crash remains necessary). However, borrowck currently skips ascribe_user_type for IAC cases (see the added FIXME comments). I believe the "args transformation" implemented in this PR won't work for borrowck with nested items (e.g., anonymous constants), and more precise handling would require adjusting the args format in MIR. I'm unsure how much of this should be addressed in this PR.

@rust-log-analyzer

This comment has been minimized.

@lapla-cogito
Copy link
Contributor Author

Now the remaining concern is how to handle the borrowck problem that I mentioned above.

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 6, 2026

That test failure isn't your fault. rustdoc is broken right now, see #152194

@lapla-cogito
Copy link
Contributor Author

Yes, I saw it just a moment ago :)

@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 6, 2026

@bors r+ rollup

thanks :3

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 6, 2026

📌 Commit 22885d2 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 6, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 6, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #151590 (cmse: don't use `BackendRepr` when checking return type)
 - #151945 (feat: Add `NonZero::<T>::from_str_radix`)
 - #152000 (Fix ICE in normalizing inherent associated consts with `#[type_const]`)
 - #152192 (Always use Xcode-provided Clang in macOS CI)
 - #152196 (bootstrap: Remove `ShouldRun::paths`)
 - #152222 (Re-add TaKO8Ki to triagebot review queue)
@rust-bors rust-bors bot merged commit a9b4c7c into rust-lang:main Feb 6, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 6, 2026
rust-timer added a commit that referenced this pull request Feb 6, 2026
Rollup merge of #152000 - lapla-cogito:ice_151027, r=BoxyUwU

Fix ICE in normalizing inherent associated consts with `#[type_const]`

Fixes #151027
Fixes #138089
Fixes #138226
Fixes #150960

When an inherent associated const is marked with `#[type_const]`, its generics expect args in the format `[Self, own_params...]`, similar to inherent associated types. However, HIR typeck's `instantiate_value_path` was constructing args in the regular associated const format `[impl_params..., own_params...]`. This mismatch caused ICEs when the `args` were later used in contexts expecting the IAC format, such as user type annotations and `borrowck`'s type ascription.
@lapla-cogito lapla-cogito deleted the ice_151027 branch February 6, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

6 participants