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

Fix `Self` type retrieval from `ProjectionTy` #778

Closed lowr closed 1 year ago

lowr commented 1 year ago

As I understand it, a ProjectionTy's substitution is in the order of the args for the associated type, and then the args for its parent (i.e. impl or trait). ProjectionTy::self_type_parameter() has been returning the first type argument in the substitution, which is not the Self type its callers would expect when the associated type has its own type parameters.

The added test shows the problem: it fails in current master as the recursive solver reports ambiguity after it gets wrong Self type and flounders in here. It hasn't been uncovered because all the traits in tests for GATs are not #[non_enumerable] (and rust-analyzer hasn't implemented GATs yet).

lowr commented 1 year ago

The failure for Book lint check seems spurious (network failure). As for Test (nightly), it's failing on this compile_fail as GATs now compile without feature gate in nightly I assume. Is there a way to apply compile_fail conditionally?

jackh726 commented 1 year ago

For that one doc test, can you just ignore it with comment to unignore when GATs stable?

lowr commented 1 year ago

Replaced compile_fail with ignore and added comment about it.

jackh726 commented 1 year ago

@bors r+

Thanks!

bors commented 1 year ago

:pushpin: Commit 7bc0c591a3f592955ea6a2fbe7928c8a52f61e6a has been approved by jackh726

It is now in the queue for this repository.

bors commented 1 year ago

:hourglass: Testing commit 7bc0c591a3f592955ea6a2fbe7928c8a52f61e6a with merge 1b32e5d9286ca48c50683177419b6f1512a49be5...

bors commented 1 year ago

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