Skip to content

fix: add CoroutineClosure to describe_field_from_ty for capture names#482

Open
SebTardif wants to merge 2 commits into
mainfrom
fix-borrowck-diag-coroutine-closure
Open

fix: add CoroutineClosure to describe_field_from_ty for capture names#482
SebTardif wants to merge 2 commits into
mainfrom
fix-borrowck-diag-coroutine-closure

Conversation

@SebTardif

Copy link
Copy Markdown
Owner

Summary

Fixes #478

describe_field_from_ty in compiler/rustc_borrowck/src/diagnostics/mod.rs matches ty::Closure | ty::Coroutine to resolve captured variable names in borrow checker diagnostics, but misses ty::CoroutineClosure. This causes borrow checker errors involving async closure captures to show "field 0" instead of the actual variable name.

Failure scenario

When the borrow checker reports an error involving a captured variable inside an async closure, the diagnostic shows the numeric field index (e.g., "cannot borrow field 0 as mutable") instead of the variable name (e.g., "cannot borrow data as mutable"). This makes errors harder to understand.

Fix

Add ty::CoroutineClosure(def_id, _) to the existing match arm alongside ty::Closure and ty::Coroutine. The closure_captures API works identically for all three closure types.

Bug origin

The CoroutineClosure variant was added for async closures (stable since Rust 1.85). This diagnostic path was not updated.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif SebTardif added bug Something isn't working I-wrong Wrong result or data corruption P-medium Medium impact: affects specific usage patterns A-diagnostics Compiler diagnostics labels Jun 19, 2026
…neClosure

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-diagnostics Compiler diagnostics bug Something isn't working I-wrong Wrong result or data corruption P-medium Medium impact: affects specific usage patterns

Projects

None yet

Development

Successfully merging this pull request may close these issues.

describe_field_from_ty missing CoroutineClosure, borrow errors show field index instead of capture name

1 participant