internal: Refactor autoderef/method resolution #11550
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
don't return the receiver type from method resolution; instead just
return the autorefs/autoderefs that happened and repeat them. This
ensures all the effects like trait obligations and whatever we learned
about type variables from derefing them are actually applied. Also, it
allows us to get rid of
decanonicalize_ty
, which was just wrong inprinciple.
Autoderef itself now directly works with an inference table. Sadly
this has the effect of making it harder to use as an iterator, often
requiring manual
while let
loops. (rustc works around this by usinginner mutability in the inference context, so that things like unifying
types don't require a unique reference.)
We now record the adjustments (autoref/deref) for method receivers
and index expressions, which we didn't before.
Removed the redundant crate parameter from method resolution, since
the trait_env contains the crate as well.
in the HIR API, the methods now take a scope to determine the trait env.
Type
carries a trait env, but I think that's probably a bad decisionbecause it's easy to create it with the wrong env, e.g. by using
Adt::ty
. This mostly didn't matter so far becauseiterate_method_candidates
took a crate parameter and ignoredself.krate
, but the trait env would still have been wrong in thosecases, which I think would give some wrong results in some edge cases.
Fixes #10058.