Bug
describe_field_from_ty in compiler/rustc_borrowck/src/diagnostics/mod.rs (line 529) matches ty::Closure(def_id, _) | ty::Coroutine(def_id, _) to resolve captured variable names for borrow checker diagnostics. ty::CoroutineClosure is not handled, causing it to fall through to the catch-all _ => which returns a numeric field index (e.g., "field 0") instead of the captured variable name.
Evidence
ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => {
let def_id = def_id.expect_local();
let var_id = self.infcx.tcx.closure_captures(def_id)[field.index()].get_root_variable();
Some(self.infcx.tcx.hir_name(var_id).to_string())
}
_ => {
// Might need a revision when the fields in trait
// `Fn(Arg, Args...)` -> (Ret1, Ret2, ..determine-)
// can be referred to by the user
None
}
Impact
When the borrow checker reports errors involving captured variables inside async closures, the error message shows "field 0", "field 1", etc. instead of the actual variable name. This makes borrow checker errors harder to understand for async closure patterns. Async closures have been stable since Rust 1.85.
PR #482
Bug
describe_field_from_tyincompiler/rustc_borrowck/src/diagnostics/mod.rs(line 529) matchesty::Closure(def_id, _) | ty::Coroutine(def_id, _)to resolve captured variable names for borrow checker diagnostics.ty::CoroutineClosureis not handled, causing it to fall through to the catch-all_ =>which returns a numeric field index (e.g., "field 0") instead of the captured variable name.Evidence
Impact
When the borrow checker reports errors involving captured variables inside async closures, the error message shows "field 0", "field 1", etc. instead of the actual variable name. This makes borrow checker errors harder to understand for async closure patterns. Async closures have been stable since Rust 1.85.
PR #482