Skip to content

Type-directed probing for inherent associated types#105961

Merged
bors merged 11 commits intorust-lang:masterfrom
fmease:iat-type-directed-probing
Feb 20, 2023
Merged

Type-directed probing for inherent associated types#105961
bors merged 11 commits intorust-lang:masterfrom
fmease:iat-type-directed-probing

Conversation

@fmease
Copy link
Member

@fmease fmease commented Dec 20, 2022

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 in rustc_hir_typeck::method::suggest which we don't have access to in rustc_hir_analysis. Not sure if there is a simple way to unify the error handling. Note that in the future, rustc_hir_analysis::astconv might not actually be the place where we resolve inherent associated types (see #103621 (comment)) but rustc_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

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

Labels

F-inherent_associated_types `#![feature(inherent_associated_types)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

8 participants