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

Fix for "ambiguous associated type" issue with ATBs #61919

Merged
merged 8 commits into from
Aug 7, 2019

Conversation

alexreg
Copy link
Contributor

@alexreg alexreg commented Jun 18, 2019

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2019
@alexreg
Copy link
Contributor Author

alexreg commented Jun 18, 2019

I'm not sure of the underlying motivation for the actual fix (2nd commit)... having diagnosed the problem, I addressed it very much "head on". If this is the right solution, then great. Either way, I should probably add a little explainer comment to the predicates_from_bound function. Let me know your thoughts, @nikomatsakis.

src/test/ui/issues/issue-61752.rs Outdated Show resolved Hide resolved
src/librustc_typeck/collect.rs Outdated Show resolved Hide resolved
src/librustc_privacy/lib.rs Outdated Show resolved Hide resolved
src/librustc_typeck/astconv.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jun 20, 2019

☔ The latest upstream changes (presumably #61983) made this pull request unmergeable. Please resolve the merge conflicts.

@Mark-Simulacrum Mark-Simulacrum added S-inactive and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2019
@alexreg alexreg added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-inactive labels Jul 11, 2019
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I spent some more time looking into this PR this morning. I actually think this is the wrong approach. The problem seems to be this:

The functon type_param_predicates in collect.rs is meant to return only the predicates that apply to the type parameter with the given def-id. i.e., if you have the defid for T, it should return predicates like T: Foo and T: Bar. But today, if you have T: Foo<Bar: Baz>, it is also returning <T as Foo>::Bar: Baz. This then confuses the code in find_bound_for_assoc_item in astconv.rs down the line, which assumes that the self-type is always just T. Threading this boolean flag works to suppress that confusion, but it's not my preferred approach.

I think what I would rather do is just add a filtering step right after this line, similar to what you find in the FnCtxt code.

Also, I think we should add a comment to type_param_predicates and get_type_parameter_bounds clarifying that they take a type parameter and return only the predicates that apply to that. I might push a comment or two to that effect to your branch.

@nikomatsakis
Copy link
Contributor

An alternative might be to add filtering around this line -- i.e., at the place where get_type_parameter_bounds is called. In that case, the contract would not be to return just bounds like X: Foo, but rather some superset including those bounds.

@nikomatsakis
Copy link
Contributor

and hence you would want to adjust the comments accordingly

@Alexendoo
Copy link
Member

Ping from triage, any updates? @alexreg

@Alexendoo Alexendoo added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2019
@alexreg
Copy link
Contributor Author

alexreg commented Jul 24, 2019

@Alexendoo Yeah sorry, I meant to get around to this, but I will finally in the next day or two.

@JohnCSimon
Copy link
Member

Ping from triage.
@alexreg Hi! Any more progress on this?

@alexreg
Copy link
Contributor Author

alexreg commented Aug 4, 2019

@JohnCSimon Ah sorry. Later today, I'm pretty confident!

@alexreg
Copy link
Contributor Author

alexreg commented Aug 5, 2019

@nikomatsakis Tried your first approach, since that made perfect sense to me, while I didn't quite get your alternative one. Hope that's alright.

@varkor Pending a rebase and adding a test for #61738, would you mind kindly reviewing this in Niko's absence? I think you know this part of the compiler reasonably well.

@Dylan-DPC-zz Dylan-DPC-zz removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 5, 2019
@Dylan-DPC-zz Dylan-DPC-zz added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2019
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 7, 2019

📌 Commit 0410e32 has been approved by nikomatsakis

@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 Aug 7, 2019
@bors
Copy link
Contributor

bors commented Aug 7, 2019

⌛ Testing commit 0410e32 with merge d4abb08...

bors added a commit that referenced this pull request Aug 7, 2019
Fix for "ambiguous associated type" issue with ATBs

Fixes #61752.

r? @nikomatsakis

CC @Centril
@alexreg
Copy link
Contributor Author

alexreg commented Aug 7, 2019

Thanks @nikomatsakis!

@bors
Copy link
Contributor

bors commented Aug 7, 2019

☀️ Test successful - checks-azure
Approved by: nikomatsakis
Pushing d4abb08 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 7, 2019
@bors bors merged commit 0410e32 into rust-lang:master Aug 7, 2019
@Centril Centril added the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-associated_type_bounds `#![feature(associated_type_bounds)]` 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

associated_type_bounds: errors with ambiguous associated type
9 participants