Skip to content

fix - don't panic on ATPIT with method-local generics - #23128

Draft
im-lunex wants to merge 2 commits into
rust-lang:masterfrom
im-lunex:fix_#23125
Draft

fix - don't panic on ATPIT with method-local generics#23128
im-lunex wants to merge 2 commits into
rust-lang:masterfrom
im-lunex:fix_#23125

Conversation

@im-lunex

@im-lunex im-lunex commented Aug 12, 2026

Copy link
Copy Markdown

when an opaque type has no generic parameters but its hidden type
references a method-local generic... instantiate would panic because
the parameter has no corresponding slot in the opaque's args

reject such uses as non-defining before it gets there and guard the
instantiate call to fall back to an error type instead of crashing.

fixes #23125

(this is my 1st PR to this repo... and please correct me if i did something wrong here for lack of experience)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That is, unfortunately, not correct. It only catches the simple case where the ATPIT has no args at all, but it can have different args.

rustc has quite complicated logic to handle that IIRC.

View changes since this review

@im-lunex

Copy link
Copy Markdown
Author

@ChayimFriedman2 thanks for review and i see.. i need a bit more time on this PR and will try to fix it as soon as possible...

@im-lunex
im-lunex marked this pull request as draft August 12, 2026 13:52
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2026
@im-lunex

Copy link
Copy Markdown
Author

this version walks the hidden type and drops any use whose params are not covered by the
opaques own args by index and kind instead of only catching the empty-args case so it also
handles non-empty but mismatched args plus const and lifetime params without panicking

@im-lunex
im-lunex marked this pull request as ready for review August 12, 2026 15:25
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Inventing your own way to handle that is not a wise idea. You should look at how rustc handles that and copy it.

@im-lunex
im-lunex marked this pull request as draft August 12, 2026 18:05
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2026
@im-lunex

Copy link
Copy Markdown
Author

i got what you are saying.. would it fix the issue if we copy rustcs remap_generic_params_to_declaration_params / ReverseMapper? im a bit confused here.. it would be great if you could guide me a bit here... (i also tried with those 2 and that worked fine and passed all tests)

@im-lunex

Copy link
Copy Markdown
Author

we can do it like the way rustc does with a ReverseMapper folder? we check opaque_type_has_defining_use_args, then map generic params back to declaration.. if we see any unmapped method-local generics, we map them to TyKind::Error / Const::Error instead of rejecting

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic; highlight: has parameters, but no args were provided in instantiate

3 participants