Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Require the ref keyword to get by-reference closure #16610

Closed
wants to merge 1 commit into from

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