about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-21 22:02:19 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-23 10:03:43 -0700
commit159a10da4c15e5d34e00d4018b352573cec7918f (patch)
treec6d05aa64f6248997959828c97143b2e4d0964da /src/rustllvm/RustWrapper.cpp
parent1e3358903d1ca150856183a696701b7dc7ceb568 (diff)
downloadrust-159a10da4c15e5d34e00d4018b352573cec7918f.tar.gz
rust-159a10da4c15e5d34e00d4018b352573cec7918f.zip
rustc: Tweak the borrow on closure invocations
This alters the borrow checker's requirements on invoking closures from
requiring an immutable borrow to requiring a unique immutable borrow. This means
that it is illegal to invoke a closure through a `&` pointer because there is no
guarantee that is not aliased. This does not mean that a closure is required to
be in a mutable location, but rather a location which can be proven to be
unique (often through a mutable pointer).

For example, the following code is unsound and is no longer allowed:

    type Fn<'a> = ||:'a;

    fn call(f: |Fn|) {
        f(|| {
            f(|| {})
        });
    }

    fn main() {
        call(|a| {
            a();
        });
    }

There is no replacement for this pattern. For all closures which are stored in
structures, it was previously allowed to invoke the closure through `&self` but
it now requires invocation through `&mut self`.

The standard library has a good number of violations of this new rule, but the
fixes will be separated into multiple breaking change commits.

Closes #12224

[breaking-change]
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions