Skip to content

Don't ICE in has_self_borrows when coroutine captures-by-ref ty is still inferred#156266

Open
swjng wants to merge 1 commit intorust-lang:mainfrom
swjng:fix/async-closure-coroutine-captures-infer-ice
Open

Don't ICE in has_self_borrows when coroutine captures-by-ref ty is still inferred#156266
swjng wants to merge 1 commit intorust-lang:mainfrom
swjng:fix/async-closure-coroutine-captures-infer-ice

Conversation

@swjng
Copy link
Copy Markdown

@swjng swjng commented May 7, 2026

Closes #155999.

coroutine_captures_by_ref_ty is a fresh next_ty_var until upvar
inference unifies it to an FnPtr. If has_self_borrows is reached
before that — e.g. when the body contains an unresolved as _ cast —
the _ => panic!() arm fires:

//@ edition:2021
fn needs_fn_mut<T>(x: impl FnMut() -> T) {
    needs_fn_mut(async || x as _)
}

Treat the Infer case like Error: report self-borrows defensively
so the closure falls back to FnOnce-only and the caller surfaces a
normal type-inference error instead of an ICE.

@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 May 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 7, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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 73 candidates
  • Random selection from 19 candidates

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 7, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

…ill inferred

`coroutine_captures_by_ref_ty` is a fresh `next_ty_var` until upvar
inference unifies it to an `FnPtr`. Reaching `has_self_borrows` before
that hits the `_ => panic!()` arm. Treat `Infer` like `Error` so the
closure falls back to `FnOnce`-only.
@swjng swjng force-pushed the fix/async-closure-coroutine-captures-infer-ice branch from 0cc1ef4 to 8f5440d Compare May 7, 2026 05:15
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.

[ICE]: async closure as _

3 participants