Closed
Description
STR
#![feature(overloaded_calls, unboxed_closures)]
use std::mem;
fn main() {
// error: cannot assign to immutable captured outer variable in a proc
//let n = 0u8;
let mut n = 0u8;
let mut f = |&mut:| {
n += 1;
println!("f.n = {}", n);
};
println!("Closure size: {}", mem::size_of_val(&f));
f();
f();
f();
println!("n = {}", n);
}
Output
Closure size: 1
f.n = 1
f.n = 2
f.n = 3
n = 0
Correct me if I'm wrong, but I think n
shouldn't need to be mutable, because f
captures (by value) a copy of n
, and modifies its copy of n
on each call. Whereas, the outer n
remains unchanged.
cc @pcwalton