rust-lang / chalk

An implementation and definition of the Rust trait system using a PROLOG-like logic solver
https://rust-lang.github.io/chalk/book/
Other
1.81k stars 179 forks source link

Generate clauses for placeholder associated types #795

Closed lowr closed 1 year ago

lowr commented 1 year ago

Currently, we don't generate clauses for placeholder associated types (TyKind::AssociatedType) except for some FromEnvs. This leads to NoSolution for goals like (IntoIterator::IntoIter)<Opaque>: Iterator where Opaque = impl IntoIterator.

For every associated type in a trait definition

trait Foo {
    type Assoc<'a, T>: Bar<U = Ty> where WC;
}

chalk with this patch generates

forall<Self, 'a, T> {
    Implemented((Foo::Assoc<'a, T>)<Self>: Bar) :- WC.
    AliasEq(<<(Foo::Assoc<'a, T>)<Self>> as Bar>::U = Ty) :- WC.
}

To be honest, I'm not entirely sure if AssociatedTyDatum::to_program_clauses() is the best place to generate those clauses in, but analogous clauses for placeholder opaque types are generated in OpaqueTyDatum::to_program_clauses(), which I modeled after.

Spotted in rust-lang/rust-analyzer#14680.

jackh726 commented 1 year ago

@bors r+

bors commented 1 year ago

:pushpin: Commit 5ffee10b889be5fa05a2c37fa88b98162e603934 has been approved by jackh726

It is now in the queue for this repository.

bors commented 1 year ago

:lock: Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase? Assuming `self` is your fork and `upstream` is this repository, you can resolve the conflict following these steps: 1. `git checkout fix/clauses-for-assoc-placeholders` *(switch to your branch)* 2. `git fetch upstream master` *(retrieve the latest master)* 3. `git rebase upstream/master -p` *(rebase on top of it)* 4. Follow the on-screen instruction to resolve conflicts (check `git status` if you got lost). 5. `git push self fix/clauses-for-assoc-placeholders --force-with-lease` *(update this PR)* You may also read [*Git Rebasing to Resolve Conflicts* by Drew Blessing](http://blessing.io/git/git-rebase/open-source/2015/08/23/git-rebasing-to-resolve-conflicts.html) for a short tutorial. Please avoid the ["**Resolve conflicts**" button](https://help.github.com/articles/resolving-a-merge-conflict-on-github/) on GitHub. It uses `git merge` instead of `git rebase` which makes the PR commit history more difficult to read. Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how `Cargo.lock` conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.
Error message ```text Auto-merging tests/test/projection.rs CONFLICT (content): Merge conflict in tests/test/projection.rs Auto-merging chalk-solve/src/clauses.rs Automatic merge failed; fix conflicts and then commit the result. ```
bors commented 1 year ago

:umbrella: The latest upstream changes (presumably #780) made this pull request unmergeable. Please resolve the merge conflicts.

lowr commented 1 year ago

I'll rebase this one after #792 lands as it's likely to cause another conflict.

jackh726 commented 1 year ago

@bors r+

bors commented 1 year ago

:pushpin: Commit 52b52cf67229d799b5adc292334f0551f2dc6afa has been approved by jackh726

It is now in the queue for this repository.

bors commented 1 year ago

:hourglass: Testing commit 52b52cf67229d799b5adc292334f0551f2dc6afa with merge e856e214eef45a03724db6dd6c3501f7841c5dc7...

bors commented 1 year ago

:sunny: Test successful - checks-actions Approved by: jackh726 Pushing e856e214eef45a03724db6dd6c3501f7841c5dc7 to master...