Closed
Description
We made closures linear so as to help prevent recursion, but the other part of that job was never done -- invoking a closure needs to be considered a unique-immutable borrow (a handy concept brought into being, at least internally, by #6801).
The goal is to prevent a program like this from compiling:
use std::hashmap::HashMap;
type Fn<'a> = 'a ||;
fn call1(c: |Fn|) {
c(|| {
c(|| ());
});
}
pub fn main() {
println!("Hello, world!");
let mut map = HashMap::new();
let mut c = 0;
call1(|f| {
error!("Inserting");
map.insert(22, c);
c += 1;
error!("Finding");
let x = map.find(&22).unwrap();
let y = *x;
assert_eq!(*x, y);
f();
error!("Found {}", *x);
assert_eq!(*x, y);
});
}
Part of #2202.
Nominating for 1.0 (backwards compat).