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:
parent
6ad11e2e25
commit
bc84e21107
@ -514,7 +514,7 @@ fn show_mutating_upvar(
|
|||||||
let upvar = ty::place_to_string_for_capture(tcx, place);
|
let upvar = ty::place_to_string_for_capture(tcx, place);
|
||||||
match tables.upvar_capture(upvar_id) {
|
match tables.upvar_capture(upvar_id) {
|
||||||
ty::UpvarCapture::ByRef(ty::UpvarBorrow {
|
ty::UpvarCapture::ByRef(ty::UpvarBorrow {
|
||||||
kind: ty::BorrowKind::MutBorrow,
|
kind: ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
format!("mutable borrow of `{}`", upvar)
|
format!("mutable borrow of `{}`", upvar)
|
||||||
@ -522,7 +522,7 @@ fn show_mutating_upvar(
|
|||||||
ty::UpvarCapture::ByValue(_) => {
|
ty::UpvarCapture::ByValue(_) => {
|
||||||
format!("possible mutation of `{}`", upvar)
|
format!("possible mutation of `{}`", upvar)
|
||||||
}
|
}
|
||||||
_ => bug!("upvar `{}` borrowed, but not mutably", upvar),
|
val => bug!("upvar `{}` borrowed, but not mutably: {:?}", upvar, val),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bug!("not an upvar")
|
bug!("not an upvar")
|
||||||
|
5
src/test/ui/closures/issue-81700-mut-borrow.rs
Normal file
5
src/test/ui/closures/issue-81700-mut-borrow.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn foo(x: &mut u32) {
|
||||||
|
let bar = || { foo(x); };
|
||||||
|
bar(); //~ ERROR cannot borrow
|
||||||
|
}
|
||||||
|
fn main() {}
|
13
src/test/ui/closures/issue-81700-mut-borrow.stderr
Normal file
13
src/test/ui/closures/issue-81700-mut-borrow.stderr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
error[E0596]: cannot borrow `bar` as mutable, as it is not declared as mutable
|
||||||
|
--> $DIR/issue-81700-mut-borrow.rs:3:5
|
||||||
|
|
|
||||||
|
LL | let bar = || { foo(x); };
|
||||||
|
| --- - calling `bar` requires mutable binding due to mutable borrow of `x`
|
||||||
|
| |
|
||||||
|
| help: consider changing this to be mutable: `mut bar`
|
||||||
|
LL | bar();
|
||||||
|
| ^^^ cannot borrow as mutable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0596`.
|
Loading…
Reference in New Issue
Block a user