-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #81717 - Aaron1011:fix/closure-diag, r=estebank
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.
- Loading branch information
Showing
3 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn foo(x: &mut u32) { | ||
let bar = || { foo(x); }; | ||
bar(); //~ ERROR cannot borrow | ||
} | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |