Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
ty::Array(ty, _) | ty::Slice(ty) => {
self.describe_field_from_ty(ty, field, variant_index, including_tuple_field)
}
ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => {
ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _) | ty::Coroutine(def_id, _) => {
// We won't be borrowck'ing here if the closure came from another crate,
// so it's safe to call `expect_local`.
//
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/async-await/async-closures/borrowck-describe-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Regression test for #478: describe_field_from_ty missing CoroutineClosure.
// Before the fix, borrow errors involving async closure captures would show
// "field 0" instead of the captured variable name, because the CoroutineClosure
// type was not recognized and fell through to the default arm.

//@ edition:2021

fn main() {
let mut x = String::from("hello");

let c = async || {
x.push_str(" world"); //~ ERROR
};

// Immutable borrow of x while async closure holds mutable borrow
println!("{}", x); //~ ERROR

let _ = c;
}