rust/src/librustc/middle
bors 1b46b007d7 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
2014-10-09 07:12:30 +00:00
..
borrowck Categorize upvars in Fn unboxed closures as freely aliasable 2014-10-05 00:24:10 -07:00
cfg
save Use slice syntax instead of slice_to, etc. 2014-10-07 15:49:53 +13:00
traits rustc: remove support for Gc. 2014-10-02 16:59:31 +03:00
trans auto merge of #17871 : michaelwoerister/rust/lldb-versioning, r=alexcrichton 2014-10-09 03:07:27 +00:00
typeck auto merge of #17784 : bkoropoff/rust/issue-17780, r=pcwalton 2014-10-09 07:12:30 +00:00
astencode.rs
check_const.rs rollup merge of #17666 : eddyb/take-garbage-out 2014-10-02 14:53:18 -07:00
check_loop.rs
check_match.rs Use slice syntax instead of slice_to, etc. 2014-10-07 15:49:53 +13:00
check_rvalues.rs
check_static_recursion.rs
check_static.rs syntax: ast: remove TyBox and UnBox. 2014-10-02 16:36:01 +03:00
const_eval.rs
dataflow.rs
dead.rs
def.rs
dependency_format.rs
effect.rs
entry.rs
expr_use_visitor.rs
graph.rs Set the non_uppercase_statics lint to warn by default 2014-10-03 20:39:56 +13:00
intrinsicck.rs rustc: remove support for Gc. 2014-10-02 16:59:31 +03:00
lang_items.rs rustc: remove support for Gc. 2014-10-02 16:59:31 +03:00
liveness.rs
mem_categorization.rs Categorize upvars in Fn unboxed closures as freely aliasable 2014-10-05 00:24:10 -07:00
pat_util.rs
privacy.rs Fix cross-crate tuple structs in statics 2014-10-02 21:31:06 +02:00
reachable.rs
region.rs
resolve_lifetime.rs
resolve.rs Use slice syntax instead of slice_to, etc. 2014-10-07 15:49:53 +13:00
stability.rs
subst.rs
ty_fold.rs rollup merge of #17666 : eddyb/take-garbage-out 2014-10-02 14:53:18 -07:00
ty.rs auto merge of #17731 : bkoropoff/rust/unboxed-by-ref, r=pcwalton 2014-10-04 00:17:04 +00:00
weak_lang_items.rs