Skip to content

Add assignment type analysis for ide-completion #20381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Aug 4, 2025

Fixes #20361

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2025
@@ -1870,3 +1882,23 @@ fn next_non_trivia_sibling(ele: SyntaxElement) -> Option<SyntaxElement> {
}
None
}

fn prev_assign_token_at_whitespace(mut token: SyntaxToken) -> SyntaxToken {
while token.kind() == SyntaxKind::WHITESPACE
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
while token.kind() == SyntaxKind::WHITESPACE
while token.kind().is_trivia()

This includes comments.

Generally it'd be better to use the parsed tree, but given completion works with malformed trees (and speculative execution is not yet a thing) I don't think it's viable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This includes comments.

ok

@@ -562,6 +562,7 @@ fn expected_type_and_name<'db>(
token: &SyntaxToken,
name_like: &ast::NameLike,
) -> (Option<Type<'db>>, Option<NameOrNameRef>) {
let token = prev_assign_token_at_whitespace(token.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? That is, why doesn't just adding ast::BinExpr to the match below works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For { x = $0 }, token is }

@ChayimFriedman2
Copy link
Contributor

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Aug 5, 2025
Merged via the queue into rust-lang:master with commit bd08e2e Aug 5, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2025
@A4-Tacks A4-Tacks deleted the fix-assign-sug branch August 7, 2025 06:00
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.

Unexpected &mut Self::XXX in completion list
3 participants