Fix panic when emitting diagnostic for closure mutable binding error

Fixes #81700

The upvar borrow kind may be `ty::BorrowKind::UniqueImmBorrow`, which is
still a mutable borrow for the purposes of this diagnostic code.
This commit is contained in:
Aaron Hill 2021-02-03 12:33:27 -05:00
parent 6ad11e2e25
commit bc84e21107
No known key found for this signature in database
GPG key ID: B4087E510E98B164
3 changed files with 20 additions and 2 deletions

View file

@ -514,7 +514,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let upvar = ty::place_to_string_for_capture(tcx, place);
match tables.upvar_capture(upvar_id) {
ty::UpvarCapture::ByRef(ty::UpvarBorrow {
kind: ty::BorrowKind::MutBorrow,
kind: ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow,
..
}) => {
format!("mutable borrow of `{}`", upvar)
@ -522,7 +522,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
ty::UpvarCapture::ByValue(_) => {
format!("possible mutation of `{}`", upvar)
}
_ => bug!("upvar `{}` borrowed, but not mutably", upvar),
val => bug!("upvar `{}` borrowed, but not mutably: {:?}", upvar, val),
}
} else {
bug!("not an upvar")