Don't build ParamEnv and do trait solving in ItemCtxts when lowering IATs by BoxyUwU · Pull Request #140247 · rust-lang/rust (original) (raw)

Fixes #108491

Fixes #125879
This was due to updating inhabited predicate stuff which I had to do to make constructing ADTs with IATs in fields not ICE

Fixes #136678 (but no test added, I don't rly care about weird IAT edge cases under GCE)

Fixes #138131
Fixes #138166
Idk random mgca/iat garbage(?) Not sure why these ICEd or why they now don't.

Avoids doing "fully correct" candidate selection for IATs during hir ty lowering when in item signatures as it almost always leads to a query cycle from trying to build a ParamEnv. I replaced it with a "simple" heuristic that assumes all aliases are equal to all other aliases and tries to unify the self type with self type of each candidate's impl.

A potential alternative would be to replace all the generic parameters in the self type with inference variables as then it would be "truly" environment agnostic. I think this is somewhat subpar as we would be weakening how much we used the self type to guide candidate selection and that's the only way for the user to attempt to specify which IAT to resolve to.

In general that's also why I think doing something hacky here instead of just throwing our hands up and saying "ItemCtxts should make inference variables" and not filtering any candidates out, is a good idea (there is no way for users to disambiguate such cases).

I'm not really sure how this interacts with #126651, though I'm also not really sure its super important to support projecting IATs from IAT self types given we don't even support T::Assoc::Other for trait-associated types so didn't give much thought to how this might fit in with that.

r? @compiler-errors
cc @fmease