rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

feat: Implement Return Position Impl Trait In Traits correctly

Open ChayimFriedman2 opened this issue 9 months ago • 4 comments

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.

ChayimFriedman2 avatar Mar 18 '25 18:03 ChayimFriedman2

This was blocked on https://github.com/rust-lang/chalk/pull/826, which I think still requires a release.

davidbarsky avatar Apr 09 '25 18:04 davidbarsky

Wondering if this also fixes #19439

snprajwal avatar May 05 '25 10:05 snprajwal

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.

ChayimFriedman2 avatar May 15 '25 22:05 ChayimFriedman2

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.

ChayimFriedman2 avatar May 19 '25 00:05 ChayimFriedman2