Skip to content

hir_typeck: Propagate async closure output into its body - #161708

Open
Dnreikronos wants to merge 2 commits into
rust-lang:mainfrom
Dnreikronos:hir_typeck/async_closure_output_diagnostic
Open

hir_typeck: Propagate async closure output into its body#161708
Dnreikronos wants to merge 2 commits into
rust-lang:mainfrom
Dnreikronos:hir_typeck/async_closure_output_diagnostic

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #161619

Rustc already knows the output type it expects from an async closure, but that type wasn't reaching the closure body during type checking. When the body returned the wrong thing, rustc compared the generated async types and suggested pinning. That sends you in completely the wrong direction.

The fix carries the coroutine signature into the body check, so the regular type error points at String::new() and says it expected ().

My first pass matched any coroutine with the same def id. It looked fine, then the iterator suite caught the problem: iter! comes through the same path but its body has no resume input. I narrowed the match to async closure bodies. I prefer that version because it uses type information rustc already has and leaves the gen path alone. The test runs with both trait solvers, and the existing iterator tests cover the case that bit me.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 17 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Async closure bodies are checked as coroutines, but their expected return
type was lost before body checking. Reuse the matching coroutine signature.

Keep this path limited to async closures because gen closures have a
different input shape.
@Dnreikronos
Dnreikronos force-pushed the hir_typeck/async_closure_output_diagnostic branch from ce23647 to 1b7d358 Compare September 12, 2026 18:27
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output type mismatch misleadingly talks about mismatched async closure types

4 participants