Closed
Description
This code fails to compile:
fn id<T>(t: T) -> T { t }
fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
fn main() {
let v = &5;
io::println(fmt!("%d", f(v)()));
}
With error:
test.rs:3:49: 3:55 error: cannot infer an appropriate lifetime due to conflicting requirements
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
^~~~~~
note: first, the lifetime cannot outlive unknown scope: 44. Please report a bug....
test.rs:3:54: 3:55 note: ...due to the following expression
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
^
test.rs:3:31: 3:58 note: but, the lifetime must be valid for the lifetime &r as defined on the block
at 3:31...
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
^~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:3:49: 3:55 note: ...due to the following expression
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
^~~~~~
error: aborting due to previous error
I was trying to return a closure containing a borrowed pointer. id
is there so that the closure isn't inferred as an @fn
.