feat: Implement Return Position Impl Trait In Traits correctly
This is a requirement to landing Return Type Notation.
Phew! That is not a lot of code, but it was pretty complicated. I'm still not 100% sure I did everything correctly, so I will appreciate a thorough review.
This was blocked on https://github.com/rust-lang/chalk/pull/826, which I think still requires a release.
Wondering if this also fixes #19439
Okay, I think this is ready for review.
I sincerely request: this PR is not small, and even less simple, and went through a rebase over a commit that changes a fundamental fact about Chalk - in which order we store generic parameters. I had many bugs, and I am sure there are more. I will really appreciate a throughout review, even more than one. If you feel like you know the ty area of rust-analyzer well enough and agree to do so, please review!
Okay, now to the boring facts:
This PR is a prerequisite to supporting Return Type Notation (and also correctly support Return Position Impl Trait In Trait in general). So it may be surprising that this PR, aimed to improve the correctness of our types, actually regresses unknown types on self (by a bit). This is due to bugs in Chalk that cause cycles, and it will be fixed by the switch to the new trait solver.
Speed and memory usage also regress (although not by much). The main reason is that there are now two queries for trait environment: trait_environment() and trait_environment_for_body() (previously the latter was a transparent wrapper over the former). Unfortunately, there isn't really something we can do to avoid that.
We probably should wait with this until the next solver changes are merged. Nevertheless, I don't expect the logic to change a lot, so I will still appreciate reviews.