-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly resolve Inherent Associated Types #103621
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
8e090c6
to
5fbc290
Compare
This comment has been minimized.
This comment has been minimized.
5d59438
to
809b831
Compare
I don't think I have enough context to do give a good review here. r? @cjgillot Feel free to reroll if you didn't want to take over the review 🙂 |
809b831
to
3aef6c6
Compare
@bors r+ |
I am not sure this is what we want, it seems like closer to what we want is for assoc types to stay unresolved into typeck so that for example: |
Rollup of 6 pull requests Successful merges: - rust-lang#103621 (Correctly resolve Inherent Associated Types) - rust-lang#103660 (improve `filesearch::get_or_default_sysroot`) - rust-lang#103866 (Remove some return-type diagnostic booleans from `FnCtxt`) - rust-lang#103867 (Remove `has_errors` from `FnCtxt`) - rust-lang#103994 (Specify that `break` cannot be used outside of loop *or* labeled block) - rust-lang#103995 (Small round of typo fixes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Out of curiosity, can it ever work? Are there cases where it's possible to infer |
projections arent injective but we still relate the substs, so |
Respect visibility & stability of inherent associated types As discussed in rust-lang#103621, this probably won't be the final location of the code that resolves inherent associated types. Still, I think it's valuable to push correctness fixes for this feature (in regards to visibility and stability). Let me know if I should write a translatable diagnostic instead and if I should move the tests to `privacy/` and `stability-attribute/` respectively. Fixes rust-lang#104243. `@rustbot` label A-visibility F-inherent_associated_types r? `@cjgillot` (since you reviewed rust-lang#103621, feel free to reroll though)
Respect visibility & stability of inherent associated types As discussed in rust-lang#103621, this probably won't be the final location of the code that resolves inherent associated types. Still, I think it's valuable to push correctness fixes for this feature (in regards to visibility and stability). Let me know if I should write a translatable diagnostic instead and if I should move the tests to `privacy/` and `stability-attribute/` respectively. Fixes rust-lang#104243. ``@rustbot`` label A-visibility F-inherent_associated_types r? ``@cjgillot`` (since you reviewed rust-lang#103621, feel free to reroll though)
Respect visibility & stability of inherent associated types As discussed in rust-lang#103621, this probably won't be the final location of the code that resolves inherent associated types. Still, I think it's valuable to push correctness fixes for this feature (in regards to visibility and stability). Let me know if I should write a translatable diagnostic instead and if I should move the tests to `privacy/` and `stability-attribute/` respectively. Fixes rust-lang#104243. ```@rustbot``` label A-visibility F-inherent_associated_types r? ```@cjgillot``` (since you reviewed rust-lang#103621, feel free to reroll though)
Respect visibility & stability of inherent associated types As discussed in rust-lang#103621, this probably won't be the final location of the code that resolves inherent associated types. Still, I think it's valuable to push correctness fixes for this feature (in regards to visibility and stability). Let me know if I should write a translatable diagnostic instead and if I should move the tests to `privacy/` and `stability-attribute/` respectively. Fixes rust-lang#104243. ````@rustbot```` label A-visibility F-inherent_associated_types r? ````@cjgillot```` (since you reviewed rust-lang#103621, feel free to reroll though)
Rollup of 6 pull requests Successful merges: - rust-lang#103621 (Correctly resolve Inherent Associated Types) - rust-lang#103660 (improve `filesearch::get_or_default_sysroot`) - rust-lang#103866 (Remove some return-type diagnostic booleans from `FnCtxt`) - rust-lang#103867 (Remove `has_errors` from `FnCtxt`) - rust-lang#103994 (Specify that `break` cannot be used outside of loop *or* labeled block) - rust-lang#103995 (Small round of typo fixes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…jackh726 Type-directed probing for inherent associated types 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 rust-lang#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 rust-lang#104251 (incl. rust-lang#104251 (comment)). Fixes rust-lang#105305. Fixes rust-lang#107468. `@rustbot` label T-types F-inherent_associated_types r? types
Type-directed probing for inherent associated types 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 rust-lang/rust#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. rust-lang/rust#104251 (comment)). Fixes #105305. Fixes #107468. `@rustbot` label T-types F-inherent_associated_types r? types
I don't know if this is the best way to do this, but at least it is one way.