Skip to content

fix: Do not use PostAnalysis TypingMode for IDE method resolution#21750

Merged
ShoyuVanilla merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:method-res-typingmode
Mar 5, 2026
Merged

fix: Do not use PostAnalysis TypingMode for IDE method resolution#21750
ShoyuVanilla merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:method-res-typingmode

Conversation

@ChayimFriedman2
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 commented Mar 4, 2026

As explained in the comments, PostAnalysis is good for most IDE things but not method resolution.

This fixes a bug which should not be impacted by this at all - return position impl trait in trait. It is currently lowered to an opaque, while it should be lowered to an anonymous associated type. But today when it is lowered as an opaque, this opaque of course has no definition and will normalize to an error, preventing method resolution on it from succeeding in some cases.

Fixes #21749.

As explained in the comments, PostAnalysis is good for most IDE things but not method resolution.

This fixes a bug which should not be impacted by this at all - return position impl trait in trait. It is currently lowered to an opaque, while it should be lowered to an anonymous associated type. But today when it is lowered as an opaque, this opaque of course has no definition and will normalize to an error, preventing method resolution on it from succeeding in some cases.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 4, 2026
@ChayimFriedman2 ChayimFriedman2 requested a review from Copilot March 4, 2026 20:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in IDE method resolution related to Return Position impl Trait in Traits (RPITIT). Previously, with_method_resolution always built an InferCtxt using TypingMode::PostAnalysis, which would attempt to reveal opaque types. However, RPITIT opaques currently lack a proper definition (they're lowered as opaque rather than as anonymous associated types), causing them to normalize to errors and preventing valid method suggestions.

Changes:

  • In with_method_resolution, replace the hardcoded TypingMode::PostAnalysis with a context-appropriate typing mode: TypingMode::analysis_in_body when inside a function body, and TypingMode::non_body_analysis() otherwise.
  • Add a regression test rpitit_with_reference verifying that method completion works correctly on &impl Foo returned from a trait method.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/hir/src/lib.rs Replace TypingMode::PostAnalysis with a body-aware typing mode selection in with_method_resolution
crates/ide-completion/src/tests/expression.rs Add regression test for RPITIT method completions via reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChayimFriedman2
Copy link
Contributor Author

Sorry for the Copilot review, I was curious to see how much it will understand from the jargon. Looks like it understand nothing and just repeats what I said, as expected 😂

@ShoyuVanilla ShoyuVanilla added this pull request to the merge queue Mar 5, 2026
Merged via the queue into rust-lang:master with commit 87f5363 Mar 5, 2026
20 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no code completion on &impl T return type

4 participants