Allow to mutate use captures
This commit is contained in:
parent
292aa87049
commit
6eb6ff62f7
2 changed files with 24 additions and 7 deletions
|
|
@ -1490,14 +1490,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
|
|||
let stmt = &bbd.statements[loc.statement_index];
|
||||
debug!("temporary assigned in: stmt={:?}", stmt);
|
||||
|
||||
if let StatementKind::Assign(box (_, Rvalue::Ref(_, _, source))) = stmt.kind
|
||||
{
|
||||
propagate_closure_used_mut_place(self, source);
|
||||
} else {
|
||||
bug!(
|
||||
"closures should only capture user variables \
|
||||
match stmt.kind {
|
||||
StatementKind::Assign(box (
|
||||
_,
|
||||
Rvalue::Ref(_, _, source)
|
||||
| Rvalue::Use(Operand::Copy(source) | Operand::Move(source)),
|
||||
)) => {
|
||||
propagate_closure_used_mut_place(self, source);
|
||||
}
|
||||
_ => {
|
||||
bug!(
|
||||
"closures should only capture user variables \
|
||||
or references to user variables"
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => propagate_closure_used_mut_place(self, place),
|
||||
|
|
|
|||
11
tests/ui/ergonomic-clones/closure/mutation.rs
Normal file
11
tests/ui/ergonomic-clones/closure/mutation.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//@ check-pass
|
||||
|
||||
#![feature(ergonomic_clones)]
|
||||
|
||||
fn main() {
|
||||
let mut my_var = false;
|
||||
let mut callback = use || {
|
||||
my_var = true;
|
||||
};
|
||||
callback();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue