You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
by-ref closure capture semantics are a backwards compatibility hazard #12831
Unboxed closures (#8622) would capture by-value, and there would be no need to add syntax for a by-reference capture. Rust's references are first-class values, unlike C++, so it's trivial to capture a reference by-value.
This would create an unboxed closure (f) with the same size as b:
let b = 5;
let f = |a| a + b;
A by-reference capture would need to be explicit:
let b = &mut 5;
let f = |a| *b = a;
I think we should consider changing the current rules, to permit dropping in unboxed closures as a backwards compatible enhancement in the future.
We do need to address the problem described here; it is not yet clear whether the suggested strategy is what we will follow, but we need to do something.
Activity
pnkfelix commentedon Mar 13, 2014
We do need to address the problem described here; it is not yet clear whether the suggested strategy is what we will follow, but we need to do something.
Assigning 1.0, P-backcompat-lang.
librustc: Copy or move upvars by value.
auto merge of #15929 : pcwalton/rust/by-ref-closures, r=alexcrichton
librustc: Require the `ref` keyword to get by-reference closure
nikomatsakis commentedon Jan 8, 2015
This is done.
Auto merge of rust-lang#12831 - fasterthanlime:proc-macro-test-in-tmp…