Type-directed probing for inherent associated types#105961
Merged
bors merged 11 commits intorust-lang:masterfrom Feb 20, 2023
Merged
Type-directed probing for inherent associated types#105961bors merged 11 commits intorust-lang:masterfrom
bors merged 11 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When probing for inherent associated types (IATs), equate the Self-type found in the projection with the Self-type of the relevant inherent impl blocks and check if all predicates are satisfied.
Previously, we didn't look at the Self-type or at the bounds and just picked the first inherent impl block containing an associated type with the name we were searching for which is obviously incorrect.
Regarding the implementation, I basically copied what we do during method probing (
assemble_inherent_impl_probe,consider_probe). Unfortunately, I had to duplicate a lot of the diagnostic code found inrustc_hir_typeck::method::suggestwhich we don't have access to inrustc_hir_analysis. Not sure if there is a simple way to unify the error handling. Note that in the future,rustc_hir_analysis::astconvmight not actually be the place where we resolve inherent associated types (see #103621 (comment)) butrustc_hir_typeck(?) in which case the duplication may naturally just disappear. While inherent associated constants are currently resolved during "method" probing, I did not find a straightforward way to incorporate IAT lookup into it as types and values (functions & constants) are two separate entities for which distinct code paths are taken.Fixes #104251 (incl. #104251 (comment)).
Fixes #105305.
Fixes #107468.
@rustbot label T-types F-inherent_associated_types
r? types