diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2021-02-03 12:33:27 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2021-02-03 12:36:24 -0500 |
| commit | bc84e211075e4c53e6fd122353f3132939e45ff9 (patch) | |
| tree | ac4c6ded68d81f3a01ac9fa84f4d6b4858614b12 /src | |
| parent | 6ad11e2e25919b75ebbc36d7910f2a1126a7e873 (diff) | |
| download | rust-bc84e211075e4c53e6fd122353f3132939e45ff9.tar.gz rust-bc84e211075e4c53e6fd122353f3132939e45ff9.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/closures/issue-81700-mut-borrow.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/closures/issue-81700-mut-borrow.stderr | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/test/ui/closures/issue-81700-mut-borrow.rs b/src/test/ui/closures/issue-81700-mut-borrow.rs new file mode 100644 index 00000000000..a27a6160142 --- /dev/null +++ b/src/test/ui/closures/issue-81700-mut-borrow.rs @@ -0,0 +1,5 @@ +fn foo(x: &mut u32) { + let bar = || { foo(x); }; + bar(); //~ ERROR cannot borrow +} +fn main() {} diff --git a/src/test/ui/closures/issue-81700-mut-borrow.stderr b/src/test/ui/closures/issue-81700-mut-borrow.stderr new file mode 100644 index 00000000000..3f564afff58 --- /dev/null +++ b/src/test/ui/closures/issue-81700-mut-borrow.stderr @@ -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`. |
