Skip to content

Conversation

@pcwalton
Copy link
Contributor

librustc: Require the ref keyword to get by-reference closure captures.

Because captured variables are now captured by value by default, this
breaks code like:

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);

As a simple change, you may wish to uniformly add the ref keyword to
all old boxed closures. This will guarantee that the semantics remain
the same.

Issue #12831.

[breaking-change]

r? @alexcrichton

captures.

Because captured variables are now captured by value by default, this
breaks code like:

    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);

As a simple change, you may wish to uniformly add the `ref` keyword to
all old boxed closures. This will guarantee that the semantics remain
the same.

Issue rust-lang#12831.

[breaking-change]
@alexcrichton
Copy link
Member

r=me, amazing!

@alexcrichton
Copy link
Member

Closing due to RFC 63.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants