diff options
| author | bors <bors@rust-lang.org> | 2014-10-09 07:12:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-09 07:12:30 +0000 |
| commit | 1b46b007d7d1acbbfb59c7e0f1307e6a378ab584 (patch) | |
| tree | c42134df1e8c0a521c4bfc3d5536be83277f0d3c /src/rustllvm/RustWrapper.cpp | |
| parent | 8f965901505268bc70923b76c8771ca5ad781c12 (diff) | |
| parent | 4d2ff432e45eedef9d15618b0b9af5378994bc46 (diff) | |
| download | rust-1b46b007d7d1acbbfb59c7e0f1307e6a378ab584.tar.gz rust-1b46b007d7d1acbbfb59c7e0f1307e6a378ab584.zip | |
auto merge of #17784 : bkoropoff/rust/issue-17780, r=pcwalton
This fixes a soundness problem where `Fn` unboxed closures can mutate free variables in the environment.
The following presently builds:
```rust
#![feature(unboxed_closures, overloaded_calls)]
fn main() {
let mut x = 0u;
let _f = |&:| x = 42;
}
```
However, this is equivalent to writing the following, which borrowck rightly rejects:
```rust
struct F<'a> {
x: &'a mut uint
}
impl<'a> Fn<(),()> for F<'a> {
#[rust_call_abi_hack]
fn call(&self, _: ()) {
*self.x = 42; // error: cannot assign to data in a `&` reference
}
}
fn main() {
let mut x = 0u;
let _f = F { x: &mut x };
}
```
This problem is unique to unboxed closures; boxed closures cannot be invoked through an immutable reference and are not subject to it.
This change marks upvars of `Fn` unboxed closures as freely aliasable in mem_categorization, which causes borrowck to reject attempts to mutate or mutably borrow them.
@zwarich pointed out that even with this change, there are remaining soundness issues related to regionck (issue #17403). This region issue affects boxed closures as well.
Closes issue #17780
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
