Closed
Description
fn main() {
let closure = |x: &uint| -> &uint { x };
}
Produces:
<anon>:2:41: 2:42 error: cannot infer an appropriate lifetime for automatic coercion due to conflicting requirements
<anon>:2 let closure = |x: &uint| -> &uint { x };
^
<anon>:1:1: 3:2 note: consider using an explicit lifetime parameter as shown: fn main<'a>()
<anon>:1 fn main() {
<anon>:2 let closure = |x: &uint| -> &uint { x };
<anon>:3 }
error: aborting due to previous error
This is suggesting to put a lifetime on the main
function, which certainly is not going to solve the problem here. The real solution is to give closure
an explicit type declaration: let closure: <'a>|&'a uint| -> &'a uint = ...;
.
Incidentally, is lifetime elision supposed to work on closures, too? Evidently it does not.