Skip to content
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

Merged
merged 2 commits into from
Nov 5, 2022

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Oct 27, 2022

I don't know if this is the best way to do this, but at least it is one way.

@fee1-dead fee1-dead added the F-inherent_associated_types `#![feature(inherent_associated_types)]` label Oct 27, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2022

r? @wesleywiser

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 27, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the iat-fix-use branch 2 times, most recently from 5d59438 to 809b831 Compare October 27, 2022 18:08
src/librustdoc/clean/mod.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/mod.rs Outdated Show resolved Hide resolved
@wesleywiser
Copy link
Member

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 🙂

@rustbot rustbot assigned cjgillot and unassigned wesleywiser Oct 31, 2022
@cjgillot
Copy link
Contributor

cjgillot commented Nov 3, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2022

📌 Commit 3aef6c6 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2022
@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 4, 2022

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: <_>::Assoc can work 🤔 Probably fine to land this so the feature is Useable Now but it would be good to record this somewhere so it doesnt get forgotten before stabilization.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2022
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
@bors bors merged commit 3450aa3 into rust-lang:master Nov 5, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 5, 2022
@fee1-dead fee1-dead deleted the iat-fix-use branch November 5, 2022 12:02
@fmease
Copy link
Member

fmease commented Nov 10, 2022

<_>::Assoc can work

Out of curiosity, can it ever work? Are there cases where it's possible to infer _ just given a projection? Projections generally aren't injective. Since we fully support inherent associated constants, are there some programs where we can already successfully infer the type just given <_>::ASSOC (where we are in the value namespace)? I could be missing something.

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 10, 2022

projections arent injective but we still relate the substs, so <_>::Assoc eq <u32>::Assoc could plausibly constrain _ eq u32

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2022
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)
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Nov 16, 2022
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2022
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2022
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)
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2023
…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
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Feb 20, 2023
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
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)]` 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants