Description
The recent attempts to improve hashmap seem to have exposed a bug in regionck where it fails to link the lifetimes of ref bindings in some situations.
A mostly minimized test case is here:
fn cb<'a,T>(x: |(&'a uint, &'a (Vec<&'static uint>, bool))| -> T) -> T {fail!()}
fn main() {
cb(|(k, &(ref v, b))| (*k, v.clone(), b));
}
This test fails to compile but (I believe) should succeed. The problem is that the lifetime of the ref v
binding inside the callback from map
is not "linked" (in regionck terminology) to the lifetime 'a
, and hence region inference infers a lifetime for v
that is too small. It was not immediately obvious what the best way is to fix this -- the code around handling ref bindings seems a bit ... off in regionck, so I need to think about it some.
Perturbing the code in various ways can workaround the issue, which is bad for making minimized test cases but good for landing the hasmap patch in the meantime!