-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regionck fails to link lifetime of ref bindings in certain situations #16994
Comments
I've run into (I think) another manifestation of this issue that forces the destructuring of a reference to a tuple from the arguments to the closure body: https://github.com/sfackler/rust-phf/blob/master/phf/src/lib.rs#L63 This works, but self.get_entry(key, |k| key == k).map(|e| {
let &(_, ref v) = e;
v
}) this does not self.get_entry(key, |k| key == k).map(|&(_, ref v)| v) |
I think this is the original problem, updated to current syntax: fn cb<'a,T>(x: Box<Fn((&'a i32, &'a (Vec<&'static i32>, bool))) -> T>) -> T {panic!()}
fn main() {
cb(|(k, &(ref v, b))| (*k, v.clone(), b));
} error:
Actually, maybe this should be using something other than Box... ugh old closures. |
If you use a boxed closure, remember to box it: fn cb<'a,T>(x: Box<Fn((&'a i32, &'a (Vec<&'static i32>, bool))) -> T>) -> T {panic!()}
fn main() {
cb(Box::new(|(k, &(ref v, b))| (*k, v.clone(), b)));
} This runs on modern rustc. |
Ah duh. Thanks! |
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:
This test fails to compile but (I believe) should succeed. The problem is that the lifetime of the
ref v
binding inside the callback frommap
is not "linked" (in regionck terminology) to the lifetime'a
, and hence region inference infers a lifetime forv
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!
The text was updated successfully, but these errors were encountered: