Skip to content

feat: Feature a "type annotations needed" diagnostic#22144

Merged
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:type-must-be-known
Apr 24, 2026
Merged

feat: Feature a "type annotations needed" diagnostic#22144
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:type-must-be-known

Conversation

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

There are two kinds of this diagnostic:

1 Some constructs, like calling or indexing, require the type to be known immediately.
2. Otherwise, if we cannot resolve the variable at the end of inference, it's an error.

This PR implements only the first kind, which is also simpler to implement. We just need to push an error in structurally_resolve_type() (as opposed to try_structurally_resolve_type() that never errors) if the type cannot be resolved, and of course also make sure we only call this function where rustc does.

The second case needs to track the origin of infer vars, and it's for another time.

Blocked on #22141.

@rustbot

This comment has been minimized.

@ChayimFriedman2 ChayimFriedman2 force-pushed the type-must-be-known branch 2 times, most recently from 169f880 to efd3409 Compare April 24, 2026 02:59
@ChayimFriedman2 ChayimFriedman2 marked this pull request as ready for review April 24, 2026 02:59
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 24, 2026
@rustbot

This comment has been minimized.

There are two kinds of this diagnostic:

 1 Some constructs, like calling or indexing, require the type to be known *immediately*.
 2. Otherwise, if we cannot resolve the variable at the end of inference, it's an error.

This PR implements only the first kind, which is also simpler to implement. We just need to push an error in `structurally_resolve_type()` (as opposed to `try_structurally_resolve_type()` that never errors) if the type cannot be resolved, and of course also make sure we only call this function where rustc does.

The second case needs to track the origin of infer vars, and it's for another time.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 24, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 24, 2026
Merged via the queue into rust-lang:master with commit 33d333a Apr 24, 2026
18 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the type-must-be-known branch April 24, 2026 10:53
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 24, 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.

3 participants