Hi everyone,
I've submitted a pull request to make captures in closures *by-value* by
default. Previously, they were all by-reference (except for `proc`).
This means that several code patterns will break. Mutating upvars is the
most common pattern:
let mut a = 10;
[ 1i, 2, 3 ].iter().map(|x| a += *x);
Change this code to:
let mut a = 10;
[ 1i, 2, 3 ].iter().map(ref |x| a += *x);
That is, add the `ref` keyword before the opening `|` of the closure.
As a simple measure to get your code up to date, you can simply prepend
`ref` en masse to your closures. This will allow you to opt into the old
semantics and will continue to work in the future.
This is a preparatory change for the move to unboxed closures. After
this, there should be no further changes necessary to get your closures
up to date; they should "just work" after closures become unboxed by
default. (However, the *types* of your closures may change in the future
once boxed closures are removed, so you may have to update
function/method/etc. signatures. But the closures themselves should not
need to change.)
Welcome to the brave new world!
Patrick
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev