Open
Description
Test case:
struct Foo;
struct FooClosure<'a>(Option<|&mut Foo|:'a>);
fn foo(closure: |&mut Foo, &int|:'static, inputs: &[int]) {
for input in inputs.iter() {
FooClosure(Some(|f| closure(f, input)));
}
}
fn main() {}
This yields an error:
/home/nmatsakis/tmp/foo.rs:7:20: 7:47 error: mismatched types: expected `core::option::Option<|&mut Foo|>` but found `core::option::Option<|&mut Foo|>` (expected concrete lifetime, but found bound lifetime parameter )
which occurs because we did not propagate the expected type and thus instantiated the type of the closure parameter with a fresh variable, rather than using a bound region. Another solution to this issue would be finding a better way to decide when we can generalize lifetimes in closure parameters, rather than relying on the closure type.
There is a workaround: just manually annotate the parameter type.