mozilla/rust — pull request #14620 by pnkfelix (2014-06-03 11:37:55+00:00)
Title: librustc: Copy or move upvars by value [breaking-change].

librustc: Copy or move upvars by value [breaking-change].

This is a commit-refactored version of PR #14501.

(pnkfelix will rebase atop master as necessary; he just wanted to transition from pcwalton's PR over to this one cleanly first.)

Original PR message follows.
----

Closes #12831.

This breaks many closures (about 10%) that look like this:

let mut sum = 0;
f.map(|x| sum += x);

Instead, rewrite them like this:

let mut sum = 0;
{
let sum_ptr = &mut sum;
f.map(|x| *sum_ptr += x);
}

Or, ideally, switch to RAII- or iterator-like patterns.

[breaking-change]