Closed
Description
This code fails to compile
fn foo(_: proc()) {}
fn bar(_: &mut int) {}
fn main() {
let mut a = 3;
do foo {
bar(&mut a);
}
}
with
test.rs:8:12: 8:18 error: cannot borrow immutable captured outer variable in a heap closure as mutable
test.rs:8 bar(&mut a);
^~~~~~
test.rs:8:17: 8:18 error: mutable variables cannot be implicitly captured
test.rs:8 bar(&mut a);
^
error: aborting due to 2 previous errors
task 'rustc' failed at 'explicit failure', /Users/alex/code/rust-opt/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/alex/code/rust-opt/src/librustc/lib.rs:396
Since procs are one-shot, I don't see why I can't capture the value mutably, the proc gains ownership of the type.
Metadata
Metadata
Assignees
Labels
No labels