Skip to content

Instantly share code, notes, and snippets.

@bblum
Created June 10, 2013 19:53
Show Gist options
  • Save bblum/5751707 to your computer and use it in GitHub Desktop.
Save bblum/5751707 to your computer and use it in GitHub Desktop.
trying, so far unsuccessfully, to exploit the lack of a value restriction on lifetime-polymorphic closures
fn expect_static(z: &'static int) {
}
fn foo<'f>(x: @mut Option<&'f fn(&'static int)>, y: &'f fn(&'static int)) {
*x = Some(y);
}
fn bar<'b>(x: @mut Option<&fn(&'b int)>) {
let z = 5;
match *x {
Some(f) => f(&z),
None => fail!("oops"),
}
}
fn main() {
let a: @mut Option<&fn<'a>(&'a int)> = @mut None;
foo(a, expect_static);
bar(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment