Skip to content

associated type suggestion ICE with const generics - #163411

Open
amirHdev wants to merge 5 commits into
rust-lang:mainfrom
amirHdev:assoc-ty-ice
Open

amirHdev wants to merge 5 commits into
rust-lang:mainfrom
amirHdev:assoc-ty-ice

Conversation

@amirHdev

@amirHdev amirHdev commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

fixes #163320
the associated type suggestion probe uses an empty param-env which leaves the next solver without the const parameter's type information

we can add necessary clauses while avoiding queries for a generic parameter's type during its own lowering

@rustbot rustbot added 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 27, 2026
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev
amirHdev marked this pull request as ready for review September 29, 2026 11:52
@rustbot

rustbot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2026
@rustbot

rustbot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@lcnr lcnr 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.

the fact that we use type relations at all when lowering in an ItemCtxt is kind of scuffed. What does this function exist for and could we somehow avoid relying on type relations while lowering item definitions entirely?

View changes since this review

@lcnr

lcnr commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

r? lcnr

@rustbot rustbot assigned lcnr and unassigned petrochenkov Sep 29, 2026
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev

Copy link
Copy Markdown
Contributor Author

Reworked this to avoid using type relations in ItemCtxt

}

ty::DeepRejectCtxt::relate_rigid_infer(tcx)
.types_may_unify_with_depth(value, impl_ty, usize::MAX)

@lcnr lcnr Oct 13, 2026 •

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.

hmm, this is a lot of complexity for a kind of minor diagnostic. But also, this code is weird. why do you both have an infcx.is_none() check and then do an if let. feels nicer to only match on infcx once. We never have infcx and not a param_env, do we? so maybe we should have a single get_ctxt_if_in_body or something that returns both InferCtxt and ParamEnv

fold_regions to replace all regions with erased is wrong. We must not replace bound regions as doing so changes types.

I feel like ideally we wouldn't try to do anything interesting when in an ItemCtxt 🤔 idk what I want here. How bad is it if you always just use the deepreject check and never try a proper can_eq?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think using DeepRejectCtxt everywhere makes sense here

we might get some false positives, like (u8, u16) matching impl<T> HasItem for (T, T) but that seems acceptable for a diagnostic
we'd need to reconsider MachineApplicable though

I'll simplify the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I noticed that DeepRejectCtxt matches unresolved projections against quite a few unrelated impls

may skipping them also loses some useful suggestions in function bodies but I think that is better than suggesting traits that do not actually apply

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@rust-bors

rust-bors Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: ICE with next-solver

5 participants